Android的:如何在AlertDialog禁用的CheckBox? [英] Android : How to disable CheckBox in AlertDialog?

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

问题描述

玉家伙...我需要创建3复选框一个警报对话框。如果点击顶部的复选框,2-另一个应点击和残疾人!!我点击他们,但没有被禁用。而且我不知道该怎么做。

Ok guys...I need to create a Alert dialog with 3 check boxes. If the top check box is clicked, 2 another one should be clicked and disabled !! I do them clicked, but not disabled. And i have no idea how to do that.

@Override 
protected Dialog onCreateDialog (int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);        
builder.setTitle("AA");             
builder.setMultiChoiceItems(mStrings, mCheckedItems, new DialogInterface.OnMultiChoiceClickListener() {                     
public void onClick(final DialogInterface dialog, int which, boolean isChecked) {


                        switch (which) {
                        case 0: {

                        if(isChecked==true)  {
                            for (int i = 1; i<=2; i++) {                                    
                            ((AlertDialog) dialog).getListView().setItemChecked(i, true);                           
                             }
                        }

                        if (isChecked==false) {
                            for (int i = 1; i<=2; i++) {                                    
                                ((AlertDialog) dialog).getListView().setItemChecked(i, false);                          
                                 }

                             break;
                        }

和这个解决方案并不好。有些时候,它不是单击所有复选框。任何人有任何想法?

And this solution is not good to. Some times its not click all checkboxes. Have anybody any idea ?

推荐答案

您应该能够在你想在你的onClick()监听器禁用两个复选框调用.setEnabled(假)。出于好奇,你为什么要使用一个for循环结构环通2项,并将其设置为检查。这在我看来,呼吁双方的.setChecked()2连续调用将简化这个proccess。

You should be able to call .setEnabled(false) on the two checkboxes you want to disable in your onClick() listener. Out of curiosity why are you using a for loop structure to loop thru 2 items and set them to checked. It seems to me that calling .setChecked() on both of the in 2 successive calls would simplify this proccess.

code样品:<​​/ P>

code sample:

//This line has to go after your dialog.show(); call
    CheckBox chkBox = (CheckBox) dialog.findViewById(R.id.yourCheckBox);
//This line will go in your OnClickListener.
    chkBox.setEnabled(false);

这篇关于Android的:如何在AlertDialog禁用的CheckBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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