无法"取消选择" ListView项 [英] Can't "unselect" listview item

查看:144
本文介绍了无法"取消选择" ListView项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能得到一个setOnItemClickListener改变个人ListView项的背景

I was able to get the background changed of an individual listview item in a setOnItemClickListener with

view.setBackgroundResource(R.color.green); 

我只需要一次,所以当其他列表项被点击,我试图选择 lv.invalidate() lv.getChildAt (0).invalidate()但都没有成功,第二原因空指针异常。任何想法把颜色了?

I only need one selected at a time so when the other list items are clicked, I tried lv.invalidate() and lv.getChildAt(0).invalidate() but neither worked and the second causes null pointer exception. Any ideas for putting the color back?

推荐答案

我在做一些分割屏幕的东西和XML选择器不工作。要设置颜色后,我结束了存储被点击的的视图查看currentlySelectedView 键,设置背景透明的,当另一种观点被点击。

I am doing some split screen stuff and xml selectors do not work. To set the color back, I ended up storing the view that was clicked in View currentlySelectedView and setting the background transparent when another view was clicked.

currentlySelectedView.setBackgroundResource(R.color.transparent);

这篇关于无法"取消选择" ListView项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆