ListView item's view in onCheckedChanged
I am trying to access a particular ListView row's View so that I can change the background colour when the selects a radio group button option.
I have extended the BaseAdapter and setup the view in the overridden getView method. By keeping track of the values at the position, the recycled views are all handled correctly and my background colour is shown correctly when getView is called.
My problem is that I want to change the background colour immediately when the user clicks the radio button. I was using something like this:
@Override
public void onCheckedChanged(RadioGroup radioGroup, int radioId)
{
View viewRow = (View) radioGroup.getParent();
开发者_Go百科 view.setBackgroundColor(colour);
}
But I don't think this is advisable, and it does not appear to work as expected (other views are also changed). For some reason, even though I also set the colour in getView, it seems to be ignored when using the above method.
Is there a good way I can access the View from this callback?
The problem was again the recycling of the views. I was not setting the colour when in the BaseAdapter's callback.
精彩评论