How to embed extra information in a View in android?
<p>I am beginning android development and in my sample application I have a ListView which I populate as follows:</p>

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

<p>The <code>getEntityLabels()</code> is a function that returns a list of strings.</p>

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

<pre><code>class Entity{
  int id;
  String label;
}
</code></pre>

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

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

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

<p>Is there a way to embed some information like id(in my case) with the views or an alternate way to get the <code>id</code>s?</p>

<p>I am aware of the way where I can override the <code>toString()</code> method of <code>Entity</code> to return label and use <code>ArrayAdapter&lt;Entity&gt;</code> instead of <code>ArrayAdapter&lt;String&gt;</code>. 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!</p>
