I'm making an app in which i need to pre checked a particular or more than one options of dynamically created checkboxes. Till now I'm able to create and get the id's of dynamically created checkboxes and store it in arraylist. My questions is how to use the values of arraylist eg:[1,2] and prechecked the options 1 and 2 of checkbox
Here is my code:
private void addCheckButtons() {
public static ArrayList<String> selchkboxlist=new ArrayList<String>();
String chk,isa;
String options[] = { op1, op2, op3, op4,op5 };
for (int i = 0; i <totalchoice; i++) {
checkedTextView=new CheckBox(this);
checkedTextView.setText("");
checkedTextView.setId(i);
checkedTextView.setText(options[i]);
checkedTextView.setTextColor(Color.BLACK);
checkedTextView.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
CheckBox cb = (CheckBox) v ;
if (((CheckBox) v).isChecked()) {
chk = Integer.toString(v.getId()+1);
selchkboxlist.add(chk);
}
else if (!((CheckBox) v).isChecked()){
chk = Integer.toString(v.getId()+1);
selchkboxlist.remove(chk);
System.out.println("RemoveCHECK="+selchkboxlist);
}
isa=String.valueOf(selchkboxlist);
String regex = "\\[|\\]";
isa=isa.replaceAll(regex, "");
}
});
rc.addView(checkedTextView);
}
}}
Aucun commentaire:
Enregistrer un commentaire