当一个项目被选中如何prevent从关闭对话框 [英] How to prevent a dialog from closing when a item is selected

查看:186
本文介绍了当一个项目被选中如何prevent从关闭对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目一个对话框:

I have a dialog with items:

final String[] items = new String[] { "item1", "item2" };

AlertDialog.Builder adb = new AlertDialog.Builder(this).setTitle("Title");
adb.setCancelable(false);
adb.setItems(items, new OnClickListener() {

    @Override
    public void onClick(DialogInterface d, int n) {
        Toast.makeText(MainActivity.this, items[n], Toast.LENGTH_LONG).show();
    });
}

AlertDialog alert = adb.create();
alert.setCancelable(false);
alert.show();

当一个项目被选中,在吐司显示,对话框关闭。如何禁用呢? 我想,该对话框仍保持打开一个项目被选中后。

When a item is selected, the Toast is shown and the dialog closes. How can I disable this? I want that the dialog still remains open after a item is selected.

推荐答案

正在使用 AlertDialog.Builder.setItems()方法,驳回对话框中的项目被点击时

You are using AlertDialog.Builder.setItems() method which dismisses a dialog when an item is clicked.

为了显示项目列表,而不必对话框解雇,你应该使用的重载之一<一href="http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setSingleChoiceItems%28java.lang.CharSequence%5B%5D,%20int,%20android.content.DialogInterface.OnClickListener%29"相对=nofollow> setSingleChoiceItems() 方式:

In order to display a list of items and not have the dialog dismissed, you should use one of the overloads of setSingleChoiceItems() method:

设置要显示的对话框的内容的产品清单,你会选择的项目通过提供侦听通知。该列表将显示在文本检查项目右侧选中标记。 点击一个项目列表中不会关闭该对话框。点击一个按钮,将关闭对话框。

Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener. The list will have a check mark displayed to the right of the text for the checked item. Clicking on an item in the list will not dismiss the dialog. Clicking on a button will dismiss the dialog.

这篇关于当一个项目被选中如何prevent从关闭对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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