0

I build an app with multi calculation system and it need every thing filled to get the result, so if the user left the checkbox without selection i would to inform him by making the text and the box of the checkbox change to "Red" like the picture in the link:

https://s15.postimg.org/kej9uc457/checkbox.jpg

if we assume my checkbox is "Yes", so how to make code for this and another one to rerun it back to it's original one?


I can make an custom xml file like this:

<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="@drawable/option_unselected" android:state_checked="false" android:color="#ff0000"/>
<item android:drawable="@drawable/option_selected"   android:state_checked="true"/>

I know how to make the condition of checking:

if(yes.isChecked())
        {check.setButtonDrawable(mContext.getResources().getDrawable(
                R.drawable.custom_checkbox));}
else
        {check.setButtonDrawable(mContext.getResources().getDrawable(
                R.drawable.custom_checkbox));}

but in this case i need two somethings:

1- checkbox image like the default one on android, then making it's box "red"

2- I need a code to make it return back to default one with black text and box

,, So how can I do that? or if anyone have another solution for my problem?

Cœur
  • 37,241
  • 25
  • 195
  • 267
amer halem
  • 121
  • 1
  • 2
  • 9

1 Answers1

0

can create another set of xml called custom_red_checkbox.xml

<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="@drawable/option_unselected_red" android:state_checked="false" android:color="#ff0000"/>
<item android:drawable="@drawable/option_selected"   android:state_checked="true"/>

and your code modify to

if(yes.isChecked())
        {check.setButtonDrawable(mContext.getResources().getDrawable(
                R.drawable.custom_checkbox));}
else
        {check.setButtonDrawable(mContext.getResources().getDrawable(
                R.drawable.custom_red_checkbox));}
zeisuke
  • 192
  • 8