How to prevent ListView items in black

I am desperately trying to fix this problem when my ListView items are highlighted. I looked through any solution I could find here on stackoverflow, and did not find any that worked for me.

The first is the ListView in LinearLayout in the ViewPager in LinearLayout.

Each element in this view is a LinearLayout containing a LinearLayout (containing a TextView) and a gallery. The gallery contains several LinearLayouts containing TextView and Imageview in FrameLayout.

This problem does not occur when you click, but when you drag it, as when scrolling your finger through the history (sometimes when the ListView scrolls with your drag and drop) the item under it is selected. In addition, this particular problem only occurs on devices where the scroll effect does not cause a rebound when scrolling.

Attempts to solve the problem are as follows:

  • Set list selector to background color in XML (Fail)
  • Set List to Alpha # 00000000 in XML (Fail)
  • Higher but programmatically
  • Above, but on the topic
  • Code that sets the selection to -1 onListItemClick
  • Removing the background from a LinearLayout list item (works in version 4.0)
  • Setting android:cacheColorHint to #00000000 (does nothing?)

Any help would be greatly appreciated. I just can't understand why he is doing this, and I really need him to stop.

Screenshot of ListView Item being HIghlighted

+6
source share
1 answer

This was the most interesting problem. The solution to this issue is even more interesting.

For some reason, what I did not try, and which no one was thinking about, was to remove android:background from LinearLayout for ListView elements.

When you remove android:background layout continues to display correctly, and the black one no longer appears.

If you have a problem like this, it will not solve, you can check the Android blog: Why is my list black?

EDIT: This works great for ICS, but caused a much bigger problem in 2.1. To completely solve this test, I had to specify android:cacheColorHint="#000000" in the ListView (and LinearLayout for good measure) in my built-in styles, as well as in the style definition that I applied to the ListView .

+8
source

Source: https://habr.com/ru/post/909308/


All Articles