我是安卓应用开发者。我想显示警报对话框包括列表视图。
当我单击列表视图的某个项目时,我想关闭警报对话框。但是,(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();
在下面使用:
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle(getText(R.string.title));
builder.setSingleChoiceItems(list, position, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int position)
{
// do something
dialog.dismiss();
}
});