1

I implemented alphabetical section headers in my ListView by adding an additional TextView element in my ListView row layout and using this additional TextView element as the header by toggling it's setVisibility property when necessary in my custom CursorAdapter. So my row layout hierarchy consists of 2 TextView's inside a vertical LinearLayout.

I want the section headers to be independent of the row element it's contained in.

Originally, clicking on the header would perform the action of the row element it's contained in, so for example if my list consisted of the elements 'Apple' 'Apricot' and 'Avocado', clicking on the header, which is labeled as 'A' would perform whatever action of the row it's attached to, which in this example would be 'Apple'. I managed to prevent this from happening by setting the TextView representing the header as clickable.

However, I am still stuck with an annoying visual effect where when I click on 'Apple', the highlighting showing my selection on click highlights the entire row, so both TextView's are highlighted. Here is an example showing what I mean. In this example, when I click 'Daft Punk', the attached header 'D' is also highlighted. Is there anyway to set it so that only the second TextView is highlighted?

deewhy
  • 31
  • 1
  • 2

1 Answers1

0

That isn't supported in a non-hacky way. If you want to properly implement a listview with sections, there's a plethora of examples using the supported multiple view types strategy.

Here are two questions for implementations and libs that do what you want:

Android listview groups Creating categories in a ListView?

A tutorial to roll your own:

http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/

If you do want to go the hacky route, in the comments for this post, he mentions intercepting touch by exploiting the focus/click event behavior bug. Cyril Mottier

Community
  • 1
  • 1
KMDev
  • 615
  • 6
  • 10