I have made a custom RelativeLayout that implements checkable for a ListView. I'm experiencing an error that occurs only on my Gingerbread running HTC Desire and NOT my JellyBean running Galaxy Nexus.
Within the custom RelativeLayout, I override the setChecked method as follows:
public class CustomRL extends RelativeLayout implements Checkable {
private boolean isChecked;
List<RelativeLayout> rl = new ArrayList<RelativeLayout>();
Context context;
public CustomRL(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
@Override
public boolean isChecked() {
return isChecked;
}
@Override
public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
this.setBackgroundColor(isChecked ? Color.parseColor("#33b5e5")
: 0x00000000);
}
}
Within my onItemClickListener, I see if the item isChecked via the method above, casting the view as customRL as follows:
@Override
public void onItemClick(AdapterView<?> listview, View v, int position,
long id) {
boolean isChecked = ((CustomRL) v).isChecked();
}
On my Galaxy Nexus, upon clicking of the item, setChecked runs before isChecked thus the latter returns whether the item has been checked correctly. On my Desire however, isChecked runs before setChecked, thus it returns the wrong value. This is reflected by the blue selected colour being set correctly on my Nexus and incorrectly on my Desire (when it is checked it isn't blue, and when it isn't checked it is blue)
This is really annoying and I've been wracking my brain for ages trying to work out why there is a difference. Anyone that can help?