我在AlertDialog中使用ListView来显示项目列表。当用户点击其中一个项目时,我想关闭对话框。我不会在对话框上有任何操作按钮。任何想法如何我会做到这一点?AlertDialog中的ListView
26
A
回答
92
你应该能够做这样的事情:
final CharSequence[] items = {"Foo", "Bar", "Baz"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Make your selection");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Do something with the selection
}
});
AlertDialog alert = builder.create();
alert.show();
这page有不同类型的对话框中其他一些例子。
0
您可以在弹出警告对话框时使用布局。以这种方式设置样式会更容易。 对于警报对话框列表,你可以这样做this
0
使用下面的代码在AlertDialog显示自定义列表
AlertDialog.Builder builderSingle = new AlertDialog.Builder(
DialogActivity.this);
builderSingle.setIcon(R.drawable.ic_launcher);
builderSingle.setTitle("Select One Name:-");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
DialogActivity.this,
android.R.layout.select_dialog_singlechoice);
arrayAdapter.add("Hardik");
arrayAdapter.add("Archit");
arrayAdapter.add("Jignesh");
arrayAdapter.add("Umang");
arrayAdapter.add("Gatti");
builderSingle.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String strName = arrayAdapter.getItem(which);
AlertDialog.Builder builderInner = new AlertDialog.Builder(
DialogActivity.this);
builderInner.setMessage(strName);
builderInner.setTitle("Your Selected Item is");
builderInner.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
builderInner.show();
}
});
builderSingle.create();
builderSingle.show();
相关问题
- 1. AlertDialog与Android中的ListView
- 2. alertdialog listview setMultiChoiceItems
- 3. alertdialog listview uncheck
- 4. 在AlertDialog中自定义ListView
- 5. AlertDialog VS Spinner vs ListView
- 6. 具有AlertDialog验证的ListView
- 7. 与ListView自定义AlertDialog
- 8. 从Android AlertDialog添加项目到ListView
- 9. listview更新与微调和AlertDialog
- 10. 在AlertDialog中的ListView中捕获CheckChanged事件
- 11. Android:在AlertDialog中的ListView只显示一行
- 12. Android:在ListView的onItemClick事件中使用AlertDialog
- 13. 在AlertDialog中更改ListView的字体大小
- 14. 如何在AlertDialog中获取ListView的元素
- 15. 在Android中使用ListView创建AlertDialog的过程是什么?
- 16. AlertDialog中的GoogleMap
- 17. BroadcastReceiver中的AlertDialog
- 18. AlertDialog中的TabHost
- 19. 问题的在AlertDialog图像使用ListView [Android的]
- 20. AlertDialog中的Android TabActivity
- 21. 如何让我的alertdialog显示listview信息?
- 22. 从显示消息到ListView适配器的过渡AlertDialog?
- 23. AlertDialog内alertdialog安卓
- 24. AlertDialog在android中
- 25. 如何将所选项目的ID从ListView传递到Android中的AlertDialog?
- 26. AlertDialog中的Android Eclipse ListView在滚动时隐藏某些文本视图
- 27. Android AlertDialog ListView瓦特/几个TextViews和一个EditText结尾
- 28. 另一个alertdialog里面的AlertDialog
- 29. AlertDialog按钮打开新的AlertDialog
- 30. 选项菜单中的AlertDialog
您还可以看到该样品警告对话框与列表视图去这里[用于演示的例子( http://goo.gl/W3a4h) – Herry 2011-12-06 19:18:43