onCheckedChanged 中 ListView 项目的视图
我正在尝试访问特定 ListView 行的视图,以便在选择单选组按钮选项时可以更改背景颜色。
我已经扩展了 BaseAdapter 并在重写的 getView 方法中设置了视图。通过跟踪该位置的值,回收的视图都得到正确处理,并且在调用 getView 时正确显示我的背景颜色。
我的问题是,当用户单击单选按钮时,我想立即更改背景颜色。我正在使用这样的东西:
@Override
public void onCheckedChanged(RadioGroup radioGroup, int radioId)
{
View viewRow = (View) radioGroup.getParent();
view.setBackgroundColor(colour);
}
但我认为这是不可取的,而且它似乎没有按预期工作(其他视图也发生了变化)。由于某种原因,尽管我也在getView中设置了颜色,但在使用上述方法时似乎被忽略了。
有没有一种好方法可以通过此回调访问视图?
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();
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题又是视图的回收。我在 BaseAdapter 的回调中没有设置颜色。
The problem was again the recycling of the views. I was not setting the colour when in the BaseAdapter's callback.