我试图创建一个列表视图对话框来显示选择列表。我的代码如下所示:Android Listview对话框在选择一个项目后不会消失
LayoutInflater factory=LayoutInflater.from(this);
final View stuckLevelDialogView=factory.inflate(R.layout.report_stuck_dialog, null);
final ListView stuckLevelListViewForDialog=(ListView)stuckLevelDialogView.findViewById(R.id.report_stuck_dialog_listview);
final String[] stuckLevelList=new String[]{"1 - You can move freely","2 - You have to be aware of your movement","3 - You can move slowly","4 - There is a traffic jam","5 - There is a serious traffic jam"};
ArrayAdapter<String> adapterForDialog=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stuckLevelList);
stuckLevelListViewForDialog.setAdapter(adapterForDialog);
final AlertDialog.Builder stuckLevelDialog=new AlertDialog.Builder(this);
stuckLevelDialog.setTitle("What stuck level is this point?");
stuckLevelDialog.setView(stuckLevelDialogView);
stuckLevelDialog.show();
然而,当我选择一个选项,onItemClick被执行,但列表视图对话框不消失,我必须手动按后退按钮。我试图调试一整天的代码,但还没有解决。请帮帮我。先进的感谢!
小幅盘整,'AlertDialog对话框= stuckLevelDialog.show()',然后在你的onItemClick'dialog.dismiss()' – Pragnani 2013-04-04 04:24:45
@Pragnani非常感谢纠正... :) – GrIsHu 2013-04-04 04:31:12
@Pragnani和Grishu:谢谢,随着你的改正,我终于解决了我的问题! – 2013-04-04 04:34:24