2

I'm coding an application that deals with 2 different CheckBoxes. When one CheckBox gets clicked, the color of the tick should be blue (instead of green), whereas the color of the other CheckBox remains green.

This is my code...

CheckBox green = (CheckBox) findViewById(R.id.greenButton); CheckBox blue = (CheckBox) findViewById(R.id.blueButton); blue.setOnCheckedChangeListener(new OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton arg0, boolean arg1) { if(arg1){ blue.setHighlightColor(Color.BLUE); Toast.makeText(getBaseContext(), "Question Marked As Partial", 4000).show(); } } }); green.setOnCheckedChangeListener(new OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton arg0, boolean arg1) { if(arg1){ blue.setHighlightColor(Color.GREEN); Toast.makeText(getBaseContext(), "Question Marked As Fully Understood!", 4000).show(); } } }); 

However, both the CheckBoxes tick colors remains green, and the Toast message doesn't get displayed, so I am guessing that the OnCheckedChangeListener is never being called.

Could someone offer any advice?

1
  • Have you tried debugging your code, or adding some System.out.println() statements, to check that your code is definately being called. My guess is that this whole piece of code isn't even being called (so the listeners aren't getting placed on the checkboxes), rather than it being a problem with the actual listeners. Commented Jun 19, 2012 at 2:55

1 Answer 1

1

If the Toast isn't appearing, it is possible that your listeners aren't actually being set on the CheckBoxes. In other words, maybe this whole piece of code isn't even being called.

If your code is in a method, make sure you're calling the method to set the listeners on the CheckBoxes, or ensure this code is in one of your main methods such as onCreate().

If you don't know already, it would be a great time to learn how to debug your code - it makes it really quick and easy to determine whether your code is being called or not.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.