我有一组复选框CheckBox labels[] = {fname,lname,company,mobno,workemail,workphone,persemail};
而且我有一个单选按钮。现在我想要的是,如果用户单击单选按钮,则所有复选框均应选中绿色的勾号。
CheckBox labels[] = {fname,lname,company,mobno,workemail,workphone,persemail};
RadioButton available,none,privte,publc;
//String [] values;
String firstname2,lastname2,comp2,mobileno2,wrkemail2,wrkphone2,persnalemail2;
Button generate;
private String output;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.startnew);
fname=(CheckBox)findViewById(R.id.fnamechk);
lname=(CheckBox)findViewById(R.id.lnamechk);
persemail=(CheckBox)findViewById(R.id.personalemailchk);
mobno=(CheckBox)findViewById(R.id.cellchk);
workemail=(CheckBox)findViewById(R.id.Workemailchk);
company=(CheckBox)findViewById(R.id.companychk);
workphone=(CheckBox)findViewById(R.id.workphonechk);
available.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//for(CheckBox cb : labels){ cb.setChecked(true); }
}
});
最佳答案
您可以在下面尝试此代码吗?
for(CheckBox cb:标签){
cb.setChecked(true);
}
遍历CheckBox数组,并将checked属性设置为true。我假设CheckBox数组包含对复选框的对象引用。
我的意思是,在创建数组之前,您具有对UI Checkbox的有效引用。CheckBox fname = (CheckBox) findViewById(R.id.fname);