Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent ListView items highlighting in Black

I have been trying desperately to fix this issue where my ListView items are highlighted. I have reviewed any solution I could find here on stackoverflow, and have found none that work for me.

First off, this is a ListView in a LinearLayout in a ViewPager in a LinearLayout.

Each Item in that Listview is a LinearLayout containing a LinearLayout (Containing a TextView) and a Gallery. The Gallery contains multiple LinearLayouts containing a TextView and Imageview in a FrameLayout.

This problem occurs, not on click but on drag, as when swiping your finger over a story (sometimes while the ListView scrolls with your drag) the item underneath becomes selected. Additionally, this particular problem only occurs on devices where the over-scroll effect does not cause a bounce when scrolling.

Attempts to solve the issue are as follows:

  • Set the List Selector to the Background Color in XML (Fail)
  • Set the List Select to Alpha #00000000 in XML (Fail)
  • The Above but Programatically
  • The Above but by theme
  • Code that sets the selection to -1 onListItemClick
  • Removing the background from list item's LinearLayout (Works on 4.0)
  • Setting android:cacheColorHint to #00000000 (does nothing?)

I just can't figure out why it's doing this and I really need it to stop.

Screenshot of ListView Item being HIghlighted

like image 632
Navarr Avatar asked Feb 24 '12 20:02

Navarr


1 Answers

This was a most interesting problem. The solution of which is even more interesting.

For some reason, what I didn't try, and what nobody thought of, was to remove android:background from the LinearLayout for the ListView items.

Upon removing android:background, the layout continues to display properly and the black no longer appears.

If you have a problem similar to this that this does not solve, you may want to check the Android Blog: Why is my list black?

EDIT: This worked fine for ICS, but elicited a much larger problem in 2.1. To completely solve the ordeal, I ended up having to specify android:cacheColorHint="#000000" to the ListView (and the LinearLayout for good measure) in my inline styles as well as in the style definition I applied to the ListView.

like image 130
Navarr Avatar answered Nov 03 '22 03:11

Navarr