Rathi J Rathi J - 5 months ago 8
JSON Question

Listview item based on JSON id value

I'm Creating the

ListView
which get the response from JSON.The JSON response contain the object like id and title.

{
"meal": [
{
"id": "1",
"title": "MEAL 1"
},
{
"id": "2",
"title": "MEAL 2"
},
{
"id": "3",
"title": "MEAL 3"
},
{
"id": "4",
"title": "MEAL 4"
}
]
}


Using
HashMap
i gave this title to the
ListView
.
OnItemClickListener
i would like to get the JSON id instead of position in
ListView
.How to do it?

This JSON id is part of url for my new activity.

Answer

Try this

lv1.setOnItemClickListener(new OnItemClickListener() {     
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      String value = lv1.getItemAtPosition(position).toString();
           //display value here 
     Log.i("TAG","Position : " + position);

     }
});

may helps you.