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 8942473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:31:37+00:00 2026-06-15T11:31:37+00:00

I have a ListView that I’m populating with a CursorAdapter like this: SimpleCursorAdapter.ViewBinder viewBinder

  • 0

I have a ListView that I’m populating with a CursorAdapter like this:

SimpleCursorAdapter.ViewBinder viewBinder = new SimpleCursorAdapter.ViewBinder() {
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
        if(columnIndex == cursor.getColumnIndex(MyTableColumns._ID))
        {
            view.setTag(cursor.getInt(columnIndex));
        }
        // some other stuff
    }
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.my_item_renderer, cursor, from, to);
adapter.setViewBinder(viewBinder);

The aim is to get the ID from the list item clicked:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Object obj = v.getTag();
    int myId = Integer.parseInt(obj.toString());
}

However this is always returning null. What am I overlooking? For now I’m just using a hidden text field but I’d like to know what I was doing wrong.

  • 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-06-15T11:31:38+00:00Added an answer on June 15, 2026 at 11:31 am

    onListItemClick() provides you with a view that is the row in the list. ViewBinder binds values to the TextViews inside this row. Thus the view you call setTag() on is not the same as the view you call getTag() on.

    You can either extend SimpleCursorAdapter so you can call setTag() on the correct view, or you can get the first child view of v in onListItemClick() and get the tag of that.

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

Sidebar

Related Questions

I have a ListView that is backed by a SimpleCursorAdapter. I'd like to be
I have a ListView that display Drawable s This is my code: @Override public
I have a ListView that is a View and this all the properties will
I have a ListView that's populated from a SimpleCursorAdapter each row containing 3 different
I have a ListView that is bounded to a CollectionViewSource. I followed this article
I have a ListView that is appearing behind two buttons. I'd like the ListView
I have a ListView that I'm populating from a custom ListAdapter . Inside the
I have a ListView that is being populated with a custom adapter. I'd like
I have a ListView that is populated with 50 items. This is the xml
I have this ListView that displays a custom user control. The custom user control

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.