I want to change the background of a listview item when the user clicks it. Kind of like the Honeycomb settings page (Although I'm not dealing with just settings so I'm not using PreferenceActivity) I have this functionality working through a resource state selector state selector except for the cases when clicking on the listview menu changes the linear layout to the right of the listview (sort of a split screen view). I'm guessing the listview looses focus so state_pressed is no longer true.
<item android:state_pressed="true">
<shape >
<solid android:color="@color/blue1" />
</shape>
</item>
Any tips to keep that listview item colored until another listview item is selected? Thanks!
EDIT:
I was able to get the background changed in a setOnItemClickListener with
view.setBackgroundResource(R.color.red);
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…