我是安卓应用开发者。我想显示 AlertDialog 包括 Listview。
当我单击 ListView 的一项时,我想关闭 AlertDialog。但是,(1)代码不起作用。
我能怎么做?
请告诉我一些建议。预谢谢!
final String[] items = new String[101] ;
for(int m = 0 ; m < items.length ; m++)
{
items[m] = Integer.toString(m) ;
}
Dialog dialog = new Dialog(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("sample list title ");
ListView modeList = new ListView(this);
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice, android.R.id.text1, items);
modeList.setAdapter(modeAdapter);
modeList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
modeList.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
{
makeToast("..test " + position );
// dialog.dismiss(); ----------------------------(1)
}
});
builder.setView(modeList);
dialog = builder.create();
dialog.show();