Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - SeparatedListAdapter - How to get accurate item position on onClick?
    text
    copied!<p>I'm using Sharkey's SeparatedListAdapter class in order to have a ListView that is separated by sections.</p> <p>The class works great, but the problem I'm having is in my <code>onListItemClick()</code> handler. If I have the following sectioned list:</p> <pre><code>--------- | A | --------- | Alex | | Allan | --------- | B | --------- | Barry | | Bart | | Billy | | Brian | --------- | C | --------- etc... </code></pre> <p>When you want to click on an item in the list, you get the <code>position</code> of the item and then do something with it.</p> <p>In my case, my list is a dynamic list of people's names. The names come from a database that is put into a <code>List&lt;CustomClass&gt;</code> before going into list. It's important for me to know the position of the item that I click on because I use the item <code>position</code> to determine other information about the person in the List object.</p> <p>Now, the problem is this: When you click an item in the list, the headers count as items, even though they are unclickable. In the above example, the positions in the list are as follows</p> <pre><code>Alex = 1 Allan = 2 Barry = 4 Bart = 5 Billy = 6 Brian = 7 </code></pre> <p>But in my original <code>List</code> object the order is like so</p> <pre><code>Alex = 0 Allan = 1 Barry = 2 Bart = 3 Billy = 4 Brian = 5 </code></pre> <p>So whenever I click on an item, like Alex, my code runs the <code>onClick</code> handler, determines that Alex is at position <code>1</code> in the and then retrieves Allans info from the <code>List</code> instead of Alex's.</p> <p>Do you see the delima here? What is the approach I should take to this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload