i want to apply onclicklistener on dynamic checkbox
and check if the checkbox is click then add the getid in ArrayList and if checkbox is unchecked then remove the getid from ArrayList
for(int i = 0; i < array.length(); i++) {
//getting product object from json array
JSONObject product = array.getJSONObject(i);
cb = new CheckBox(getApplicationContext());
cb.setText(product.getString("service_name"));
cb.setId(product.getString("id"));
cb.setTag(product.getString("id"));
linearMain.addView(cb);
}
buttons.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(cb.isChecked())
{
testoo.add(cb.getId());
}
else {
testoo.remove(cb.getId());//checkbox unchecked
}
}
});
}
});
Aucun commentaire:
Enregistrer un commentaire