列表项对话框
启动一个列表项对话框,如图所示:

代码实现的片断如下所示:
return new AlertDialog.Builder(AlertDialogSamples.this)
.setTitle(R.string.select_dialog)
.setItems(R.array.select_dialog_items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String[] items = getResources().getStringArray(R.array.select_dialog_items);
new AlertDialog.Builder(AlertDialogSamples.this)
.setMessage("You selected: " + which + " , " + items[which])
.show();
}
})
这里使用了setItems()表示设置几个不同的项目,从res/values/array.xml文件中取得select_dialog_items的内容,这部分内容如下所示:
<string-array name="select_dialog_items">
<item>Command one</item>
<item>Command two</item>
<item>Command three</item>
<item>Command four</item>
</string-array>
这里的Item也设置了点击函数,因此它们被点击后,也会弹出新的对话框。
浙公网安备 33010602011771号