2012-04-24 71 views
0
 for(int i=3;i<plates1.length();++i) 
     { 
      final CheckBox cb=new CheckBox(this); 

      JSONObject jObj1 = plates1.getJSONObject(i); 
      String date=jObj1.getString("Name"); 
      cb.setText(date); 
      cb.setId(i); 
     } 

我有我的for循环这里。我已经使用for循环创建了复选框,但我无法弄清楚如何在使用复选框ID的同时选择两个复选框。你能帮我解决吗?Android检查多个复选框

回答

0
for(int i=3;i<plates1.length();++i) 
     { 
      final CheckBox cb=new CheckBox(this); 

      JSONObject jObj1 = plates1.getJSONObject(i); 
      String date=jObj1.getString("Name"); 
      cb.setText(date); 
      cb.setId(i); 
      parentView.addView(cb) // you should add it in parent layout 
     } 

的,那么这是你如何访问它..

((CheckBox)parentView.findViewById(3)).setChecked(true) // i took the first check box added 

// do the same with others 
+0

谢谢沙,但我怎么分配这一个变量?我打算使用if循环,当我选择两个复选框时,我将添加一些活动 – 2012-04-24 14:12:50