How To Add Action Dynamically For Multiple Checkbox On Android?
In my project rows are added dynamically to the table depending on selected items from database. This table contains a column with checkbox How can I set action for each checkbox t
Solution 1:
What you can do is:
Solution 2:
I would say yes.
FrameLayoutyourlayout= (FrameLayout) findViewById(R.id.container);
CheckBox[] check = newCheckBox[10];
check[0] = newCheckBox(this);
yourlayout.addView(check[0]);
check[0].setOnClickListener(newOnClickListener() {
publicvoidonClick(View v) {
Toast.makeText(getApplicationContext(), "Hi, this is working fine", Toast.LENGTH_SHORT).show();
}
});
I don't know what kind of layout you are using, but this example works for me.
Edit: as said above, setting a tag is a nice way to know what checkbox was pressed.
Post a Comment for "How To Add Action Dynamically For Multiple Checkbox On Android?"