What should I do to use custom checkboxes if I add my checkboxes dynamically in my code? (On the java code not on the XML files.) I'm following this tutorial, but using it I can't achieve my goal.
For example, I have a tableLayout and I want to add a checkbox for each new row I have.
Thank you all.
If you want to add custom checkboxes try this:
StateListDrawable stateList = new StateListDrawable();
int statePressed = android.R.attr.state_pressed;
int stateChecked = android.R.attr.state_checked;
stateList.addState(new int[] {-stateChecked}, new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.check_3)));
stateList.addState(new int[] {stateChecked}, new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.check_1)));
stateList.addState(new int[] {statePressed}, new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.check_2)));
final CheckBox box = new CheckBox(this);
box.setButtonDrawable(stateList);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With