Android - how to set an ArrayList ListView with a field from an object but also track the items id
<p>I declare this adapter:</p>

<pre><code>ArrayAdapter&lt;Problem&gt; adapter;
</code></pre>

<p>I also declare this this ArrayList:</p>

<pre><code>ArrayList&lt;Problem&gt; problems = new ArrayList &lt;Problem&gt;( );
</code></pre>

<p>My Problem class has only 2 fields: problemId and problemName.</p>

<p>I make a call to remote db and populate the data like this:</p>

<pre><code>                    for ( int i = 0; i &lt; obj.length(); i++ )
                    {
                        JSONObject o = obj.getJSONObject(i);                                

                        problem_title = o.getString("problem_title");
                        problem_id = o.getString("problem_id");

                        Problem p = new Problem ( );
                        p.setProblemId(problem_id);                         
                        p.setProblemId(problem_title);

                        problems.add( p );                                                      
                    }

                    adapter.notifyDataSetChanged();     
</code></pre>

<p>So the stuff that gets displayed to the screen is object reference, but what I want displayed is  the name, and when a user clicks that item, I should also be able to retrieve the id of that item in my listener here:</p>

<pre><code>ListView lv = getListView();
lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new OnItemClickListener() 
{
    public void onItemClick(AdapterView&lt;?&gt; parent, View view,
        int position, long id) 
    {
      // When clicked, show a toast with the TextView text
      Toast.makeText(getApplicationContext(), (( TextView ) view).getText(),
          Toast.LENGTH_SHORT).show();

      // For now just do something simple like display a responsive message
      Log.d( "MyProblemsActivity" , "A choice was made from the list: " + (( TextView ) view).getText() );
      Log.d( "MyProblemsActivity" , "position: " + position );
      Log.d( "MyProblemsActivity" , "id: " + id );

    }
  });        
</code></pre>

<p>Help is much appreciated!!!!</p>

<p>Thanks!</p>
