ListView控件在AlertDialog [英] ListView in AlertDialog

查看:282
本文介绍了ListView控件在AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的AlertDialog一个ListView显示的项目清单。当用户点击的项目之一,我想对话框关闭。我也不会在对话框上的任何操作按钮。如何我会做到这一点任何想法?

I am using a ListView in an AlertDialog to display a list of items. When the user clicks on one of the items, I want the dialog to close. I would not have any action buttons on the dialog. Any ideas on how I would accomplish this?

推荐答案

您应该能够做这样的事情:

You should be able to do something like:

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();

页面有不同类型对话框中的其他一些例子。

This page has some other examples of different types of Dialogs.

这篇关于ListView控件在AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆