YOu need to set the list in the dialogue box... You have extended the list activity for the bcjgrnd screen..hence the error..
and after the set the content view..get the list view and set the adapter..in your changeConnPref method. something list this.... ur_listView= (ListView) mDialog.findViewById(R.id.hi_fi_list); ur_listView.setAdapter(bConnAdapter); On Mon, Dec 29, 2008 at 11:37 AM, zcj0429 <[email protected]> wrote: > > Hi: > I'm now looking for a method to create listview in a dialog. The > method I'm now using is create an adaptor called connAdapter, the code > is: > > --------------------------------------------------------------------------------------- > public class ConnAdapter extends BaseAdapter{ > private final Context context; > private List<String> conns; > > public ConnAdapter(List<String> conns, Context context) { > this.conns = conns; > this.context = context; > } > > @Override > public int getCount() { > return conns.size(); > } > > @Override > public Object getItem(int position) { > return conns.get(position); > } > > @Override > public long getItemId(int position) { > return position; > } > > @Override > public View getView(int position, View convertView, ViewGroup > parent) > { > String conn = conns.get(position); > > LayoutInflater inflate = LayoutInflater.from(context); > > View v = inflate.inflate(R.layout.conn_list_row, parent, > false); > > TextView buddyText = > (TextView)v.findViewById(R.id.conn_name); > buddyText.setText(conn); > > return v; > } > > } > > ------------------------------------------------------------------------------------- > > and the code which create the dialog is : > > > -------------------------------------------------------------------------------------- > public void changeConnPref(){ > List<String> conns = new ArrayList<String>(); > conns.add("WIFI"); > conns.add("Bluetooth"); > mDialog = new Dialog(this); > mDialog.setContentView(R.layout.connpreference); > mDialog.setTitle("Connection Preference"); > ConnAdapter bConnAdapter = new ConnAdapter(conns, this); > setListAdapter(bConnAdapter); > > Button bOk = (Button) mDialog.findViewById(R.id.pre_OK); > bOk.setOnClickListener(new OnClickListener() { > public void onClick(final View v) { > > mDialog.dismiss(); > } > }); > > Button bCancel = (Button) > mDialog.findViewById(R.id.pre_cancel); > bCancel.setOnClickListener(new OnClickListener() { > public void onClick(View v) { > mDialog.cancel(); > } > }); > > mDialog.show(); > } > > > --------------------------------------------------------------------------------------------------- > > The xml file of the dialog view is: > > > ---------------------------------------------------------------------------------------------------- > > <?xml version="1.0" encoding="utf-8"?> > <AbsoluteLayout android:id="@+id/conn_pre" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > xmlns:android="http://schemas.android.com/apk/res/android"> > <ListView android:id="@+id/conn_list" android:layout_width="135px" > android:layout_height="218px" android:layout_x="32px" > android:layout_y="43px"> > </ListView> > <Button android:id="@+id/up" android:layout_width="wrap_content" > android:layout_height="wrap_content" android:text=" Up " > android:layout_x="216px" android:layout_y="72px"> > </Button> > <Button android:id="@+id/down" android:layout_width="wrap_content" > android:layout_height="wrap_content" android:text="Down" > android:layout_x="217px" android:layout_y="148px"> > </Button> > <Button android:id="@+id/pre_OK" android:layout_width="wrap_content" > android:layout_height="wrap_content" android:text=" OK " > android:layout_x="55px" android:layout_y="337px"> > </Button> > <Button android:id="@+id/pre_cancel" > android:layout_width="wrap_content" > android:layout_height="wrap_content" android:text="Cancel" > android:layout_x="152px" android:layout_y="335px"> > </Button> > </AbsoluteLayout> > > > ------------------------------------------------------------------------------------------------------------- > > But when the dialog shows up, the listview is not in the dialog, but > in the background screen. Anyone can help? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

