Search code examples
javaandroideclipseandroid-listviewandroid-checkbox

When CheckBox is checked change the text color in ListView row


I have a TO DO List and when the CheckBox is ticked. I want the color in the ListView row where the CheckBox is to change.

This is the code I have done but it does not work.

public class CheckBoxCheck extends Activity{

CheckBox check;

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

   check = (CheckBox) findViewById(R.id.checkBox1);
   check.setOnCheckedChangeListener(new OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked){
            check.setBackgroundColor(Color.BLUE);
        }else{
            check.setBackgroundColor(Color.BLACK);
        }

    }
});

}
 }

Could You Please Help.


Solution

  • This should be pretty easy. The checkbox can have a text associated. So simply put the text in the checkbox and give the text a color which is a . In the selector xml you can easily specify the colors for the normal and the checked state.