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?