Alertdialog框来自每个功能 [英] Alertdialog box getting from every function

查看:66
本文介绍了Alertdialog框来自每个功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用函数显示特定选中复选框的警告框这是我的代码

 call.setOnClickListener( new  View.OnClickListener(){
@ Override
public void onClick(查看视图){
ListView mainListView = mDrawerList;
checkbox =(CheckBox)mainListView.getChildAt( 0 )。findViewById(R.id.checkBox1);
checkbox1 =(CheckBox)mainListView.getChildAt( 1 )。findViewById(R .id.checkBox1);
checkbox2 =(CheckBox)mainListView.getChildAt( 2 )。findViewById(R.id.checkBox1);
checkbox3 =(CheckBox)mainListView.getChildAt( 3 )。findViewById(R.id.checkBox1);
for ( int x = 0 ; x< mainListView.getChildCount(); x ++){

if (checkbox.isChecked()){
getMain();

}

else if (checkbox1。 isChecked()){
second();

}
else if (checkbox2.isChecked()) {
third();

}
else if (checkbox3.isChecked()) {
fourth();

} else {
getMain();

}
}
}
});





但是有4个警告显示!!



我尝试过:



但是当我在不使用复选框的情况下调用单个函数时



 call.setOnClickListener( new  OnClickListener(){
public void onClick(查看v){
// TODO自动生成的方法存根
getMain();
}

});



现在只有一个警告框

解决方案

因为在每种情况下你都在调用: findViewById(R.id.checkBox) 1

I want to show alertbox of particular selected checkbox using function this is my code

call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ListView mainListView = mDrawerList;
                checkbox = (CheckBox) mainListView.getChildAt(0).findViewById(R.id.checkBox1);
                checkbox1 = (CheckBox) mainListView.getChildAt(1).findViewById(R.id.checkBox1);
                checkbox2 = (CheckBox) mainListView.getChildAt(2).findViewById(R.id.checkBox1);
                checkbox3 = (CheckBox) mainListView.getChildAt(3).findViewById(R.id.checkBox1);
                for (int x = 0; x < mainListView.getChildCount(); x++) {
 
                    if (checkbox.isChecked()) {
                        getMain();
 
                    }
 
                    else if (checkbox1.isChecked()) {
                        second();
 
                    }
                    else if (checkbox2.isChecked()) {
                        third();
 
                    }
                    else if (checkbox3.isChecked()) {
                        fourth();
 
                    } else {
                        getMain();
 
                    }
                }
            }
        });



but there is 4 alertbox is displaying !!

What I have tried:

But when i calling single function without using checkbox

call.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
        // TODO Auto-generated method stub
            getMain();
        }

    });" 


Now only one alertbox is there

解决方案

Because in every case you are calling: findViewById(R.id.checkBox1)


这篇关于Alertdialog框来自每个功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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