How to get the unique id of an item in listview created using simpleadapter in onListItemClick
After searching lot of similar questions posted on stackoverflow and other forums for couple of days I decided to post this since I couldn't find the answer I was looking for (I might have missed the obvious).
Let us say I have a arraylist of hashmaps which in turn contains 2 items , 1 - a unique ID which was retrieved from a database table and 2 - name of a country.
I have defined my listview in a layout xml, and also have a separate layout with the country name as a text view in it. I have an activity class which extends listactivity for which I have set the contentview as the layout which contains the listview layout.
I have created a simpleadapter using this hashmap and with the countryname field name (I want only the country name to be displayed in the list view) - view comes up fine, no issues there.
Now when then an item on the view is clicked the onListItemClick method gets called as expected and I'm able to retreive the countryname based on the position. But what I actually want to get is the ID of the country which was originally stored in the arraylist(hashmap) but was not included in the list of items to be displayed in the listview. Is there any way to get that ID? When I use a cursor adapter, the same onlistitemclick is able to give me the uniqueID of the data in the ID parameter, but when I use a simpleadapter the id 开发者_高级运维passed on the call back seems to be same as the position.
Any lead on this is highly appreciated, it is quiet possible I might have missed the obvious.
Why don't you just extend the simpleadapter to have an instance variable that can be set to the id?
精彩评论