0

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.

Rathi J
  • 849
  • 9
  • 16
  • This question is already answered many times.... – karan Jun 25 '16 at 07:21
  • 2
    Possible duplicate of [How to parse JSON Array (Not Json Object) in Android](http://stackoverflow.com/questions/18977144/how-to-parse-json-array-not-json-object-in-android) – karan Jun 25 '16 at 07:22
  • @karan.. My question is to pass the id value to get new activity. This JSON id is url for my new activity. – Rathi J Jun 25 '16 at 07:27
  • @Karan If you say it has dublicate put answer to this question, i will make accepted answer. – Rathi J Jun 25 '16 at 07:39
  • 1
    http://stackoverflow.com/questions/21720759/convert-a-json-string-to-a-hashmap – karan Jun 25 '16 at 07:40
  • 1
    http://stackoverflow.com/questions/22011200/creating-hashmap-from-a-json-string – karan Jun 25 '16 at 07:40
  • I also say that please don't parse by your self. Use GSON which is google's auto parse. And try to use Model structure. – karan Jun 25 '16 at 07:42
  • I converted it to HashMap. now my question is how to get the particular id from the HashMap :( – Rathi J Jun 25 '16 at 07:42

1 Answers1

0

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.

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48