2

I have a SimpleAdapter that populates a ListView, but when the user presses an item I'd like to be able to get the original HashMap that was used to populate the row that was clicked. Unfortunately it seems that all I can get back is an Object which only supports toString(). Having the String from the view the user clicked is not useful since it is not a unique identifier.

How can I get my data back for the row the user clicked on?

ArrayList<HashMap<String, String>> reformedBundle = new ArrayList<HashMap<String, String>>();
// [...]
mResultsAdapter = new SimpleAdapter(this,
    reformedBundle, R.layout.resultrow,
    new String[] { "ProviderName", "Street", "City" },
    new int[] { R.id.tvField1, R.id.tvField2, R.id.tvField3
});

lvResults.setAdapter(mResultsAdapter);

lvResults.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
            // Here's where I want to get the original HashMap<String, String> so I can query other keys in the HashMap
        }
    });
Nick Betcher
  • 1,871
  • 4
  • 18
  • 25

1 Answers1

2

I stored in a member variable.

private ArrayList<HashMap<String, String>> reformedBundle;

...

lvResults.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
        HashMap<String, String> map = reformedBundle.get(pos);
    }
});
user802421
  • 7,418
  • 5
  • 36
  • 62