3

i am newbie to android, I wanted to implement dynamically JSON data to my android listView, I have only to objects in JSON file this are dealname and discount.

I checked all questions and tutorials but when i implemented those codes in application, neither one is running. I just wanted to ask, to implement such JSON data, should i need to parse data and convert into String array so simple listview work, or i need to implement custom listview? Plz your suggestions will help to solve this assignment..

Thanks in advance.

ashutosh
  • 759
  • 5
  • 13
  • 34
  • 2
    you need to parse the json data into simple array and then set that array to adapter. – MKJParekh Dec 12 '11 at 11:34
  • more see this tutorial http://mobile.dzone.com/news/android-tutorial-how-parse and if finding more than 1 field in a json object see this to add multiple object to listview http://www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/ – MKJParekh Dec 12 '11 at 11:37

3 Answers3

7

Look at these two tutorials, In these Json object are displayed in Custom ListView, I think this is what you needed,

Android Putting Custom Objects in ListView

Populate Listview from JSON

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151
  • Frankenstein and user370305 thanks for ur suggestions... It will help me alot.. Thank u very much... – ashutosh Dec 13 '11 at 09:09
  • 1
    Second link is expired. – theblang Oct 24 '13 at 16:42
  • 1
    While this answer may theoretically answer the question, [it is better](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – hichris123 Mar 19 '14 at 21:26
2

For simple example no need of custom list view. you can work with simple list view.

  • Parse the JSON data retrieve the data
  • store them in a list and pass that list as an argument to the adapter
  • set the adapter to the list view.
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
0

You will need custom list adapter, and possibly custom list entry.

Assuming you have already parsed your JSON and have JSON Array, this adapter will have to: - provide amoubnt of entries in JSON arary - create and populate entry views on demand for certain list entry identified by position. Keep in mind, that list entries are reusable ( and they should be reused to reduce amount of object alloaction)

If there is a lot of data in JSON, better approach would be to use GSON pull parser and some databinding , to create java objects istead of built in JSON parser

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35