Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:39:51+00:00 2026-05-26T01:39:51+00:00

I’m using Sharkey’s SeparatedListAdapter class in order to have a ListView that is separated

  • 0

I’m using Sharkey’s SeparatedListAdapter class in order to have a ListView that is separated by sections.

The class works great, but the problem I’m having is in my onListItemClick() handler. If I have the following sectioned list:

---------
| A     |
---------
| Alex  |
| Allan |
---------
| B     |
---------
| Barry |
| Bart  |
| Billy |
| Brian |
---------
| C     |
---------
etc...

When you want to click on an item in the list, you get the position of the item and then do something with it.

In my case, my list is a dynamic list of people’s names. The names come from a database that is put into a List<CustomClass> 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 position to determine other information about the person in the List object.

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

Alex = 1
Allan = 2
Barry = 4
Bart = 5
Billy = 6
Brian = 7

But in my original List object the order is like so

Alex = 0
Allan = 1
Barry = 2
Bart = 3
Billy = 4
Brian = 5

So whenever I click on an item, like Alex, my code runs the onClick handler, determines that Alex is at position 1 in the and then retrieves Allans info from the List instead of Alex’s.

Do you see the delima here? What is the approach I should take to this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:39:52+00:00Added an answer on May 26, 2026 at 1:39 am

    You could use setTag() for your every item in the listView. This can be done by adding this tag before you return the view from getView() function in the listAdapter. lets say your list adapter return convertView ,then in the list adapter.

        public View getView(int position, View convertView, ViewGroup parent) {
                ViewHolder holder;
                if (convertView == null)
                {
                    convertView = mLayoutInflater.inflate(R.layout.morestores_list_item, null);
                    holder = new ViewHolder();
    
                    convertView.setTag(holder);
                } else {
                    holder = (ViewHolder) convertView.getTag();
                }
                // populate holder here, that is what you get in onItemClick.
                        holder.mNameofItem = "NameofaPerson";
                return convertView;
            }
    
    static class ViewHolder {
            TextView mName;
            Button mAction;
            ImageView mLogo;
                // use this class to store the data you need, and use appropriate data types.
                String mNameofItem.
        }
    

    when ever you get a click on the list item, use

    public void onItemClick(AdapterView<?> arg0, View convertView, int arg2,
                long arg3) {
                    ViewHolder holder = (ViewHolder) convertView.getTag();
                    // holder has what ever information you have passed.
                    String nameofItemClicked = holder.mNameofItem;
                    // access the information like this.
        }
    

    This approach doesn’t need the position of the item in the list, just wanted to let you know different approach.

    HTH.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I am doing a simple coin flipping experiment for class that involves flipping a
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.