Android 列表对话框 setItems
程序员文章站
2022-08-02 19:55:30
private Button button; private final CharSequence[] items = { "北京", "上海", "广州" }; @Override protected void onCreate(Bundle savedInstanceState) { super... ......
private button button; private final charsequence[] items = { "北京", "上海", "广州" }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button = (button) findviewbyid(r.id.button); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub alertdialog.builder builder = new alertdialog.builder(mainactivity.this); builder.settitle("请选择以下城市"); // builder.setmessage("请选择以下城市"); // 使用setmessage会覆盖setitems内容 builder.setitems(items, new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // todo auto-generated method stub charsequence sequence = items[which]; toast.maketext(mainactivity.this, "select " + sequence, 1).show(); } }); alertdialog dialog = builder.create(); dialog.show(); } }); }
上一篇: 淘集集因欠商家货款面临“暴雷”