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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:52:12+00:00 2026-06-11T09:52:12+00:00

I am beginning android development and in my sample application I have a ListView

  • 0

I am beginning android development and in my sample application I have a ListView which I populate as follows:

ListView listView = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getEntityLabels());
listView.setAdapter(adapter);

The getEntityLabels() is a function that returns a list of strings.

In the underlying model, the labels are not unique. Instead each entity has an id field which is unique for every entity.

class Entity{
  int id;
  String label;
}

When the user clicks on an item in the ListView, I would like to do some processing. So, I added an ItemClickListener as follows:

listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
{               
      //I would like to get the Id of the Entity, not just the label
}});

The processing depends on the id of the entity. However, as the view in the list is just a text and contains only the label, I cannot access it.

Is there a way to embed some information like id(in my case) with the views or an alternate way to get the ids?

I am aware of the way where I can override the toString() method of Entity to return label and use ArrayAdapter<Entity> instead of ArrayAdapter<String>. However, I am not looking for this. I am looking for a more generic way where I can embed any information with any View, if possible!

  • 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-11T09:52:13+00:00Added an answer on June 11, 2026 at 9:52 am

    You can use tags and assign tag to each view set in your adapter. Then you can read your tag from clicked view in OnClickListener and proceed. As tag can be anything (Object) you like that should solve your problem. See setTag() and related.

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

Sidebar

Related Questions

I've borrowed the following code from Wei-Meng Lee's "Beginning Android Application Development": import android.content.Context;
I am beginning Android app development and I would like to know which device
I'm reading Beginning Android Application Development by Wei-Mung Lee. I'm confused about custom actions
I'm beginning to learn Android Development and I have a bar at the top
I have been following a book on Android Beginning Android Application. I have been
I'm beginning with android NDK. I have to compile a native library for the
I am new to android development but in the past few weeks I have
I have bought a book (Beginning Android Games) by Mario Zechner. On page 149,
We have been getting a new error in our Android app since beginning of
I'm beginning Android development and I am concerned about leaks. I think thread leaks

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.