2012-03-02 87 views
0

我正在尝试使用一组复选框进行自定义对话框,并且我想验证它们,以便如果用户单击确定按钮而不选择其中任何一个,则会向用户显示一条消息,要求他们选择至少一个选项。如果他们有(选择至少一个选项),则会显示一条消息,说明用户检查了哪些复选框。如何验证自定义对话框中的复选框?

我无法继续验证,任何人都可以帮助我,并确定任何人有任何想法来验证自定义对话框中的复选框吗?

Button conditions_btn=(Button)findViewById(R.id.conditions_btn); 
conditions_btn.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 
     final Dialog ConditionsDialog =new Dialog(ProfileView.this); 
     ConditionsDialog.setContentView(R.layout.diseases); 
     ConditionsDialog.setTitle(" select your health condition "); 

     DCB1=((CheckBox) ConditionsDialog.findViewById(R.id.CB1)); 
     DCB2=((CheckBox) ConditionsDialog.findViewById(R.id.CB2)); 
     DCB3=((CheckBox) ConditionsDialog.findViewById(R.id.CB3)); 
     DCB4=((CheckBox) ConditionsDialog.findViewById(R.id.CB4)); 

     Diseses_ok_btn= ((Button) ConditionsDialog.findViewById(R.id.ok_button)); 
     Diseses_ok_btn.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       //validate the check boxes 
       if( DCB1.isChecked()== false&&DCB2.isChecked()==false&&DCB3.isChecked()==false&&DCB4.isChecked()==false) { 
        showMessage(" please select your health condition "); 
       } else {  
       // what should i do here to get the check boxes that have been checked ?? 
       } 
      } 
     }); 

     Diseses_cancel_btn=((Button)ConditionsDialog..findViewById(R.id.cancel_button)); 
     Diseses_cancel_btn.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       ConditionsDialog.dismiss(); 
      } 
     }); 

     ConditionsDialog.show(); 
    } 
}); 
+0

请添加更多标签(包括编程语言) – smcg 2012-03-02 18:44:52

+0

我已经搜查过网,但我没有发现溶胶我的问题,请任何机构可以帮助我吗? – user 2012-03-05 09:26:59

回答

0

我可能误解了你的问题,但在这里不用...

我不知道如何访问名字你的疾病,但我会做类似这样的东西在你的“验证模块“:

String msg = "You have selected:"; 
if (DCB1.isChecked()) { 
    msg += "\n DCB1"; //or get the disease name 
} 
if (DCB2.isChecked()) { 
    msg += "\n DCB2"; //or get the disease name 
} 
if (DCB3.isChecked()) { 
    msg += "\n DCB3"; //or get the disease name 
} 
if (DCB4.isChecked()) { 
    msg += "\n DCB4"; //or get the disease name 
} 
showMessage(msg); 
+0

你已经理解我的问题。非常感谢你帮助我 – user 2012-03-08 19:35:02