JSON object to listView

2019-01-15 20:44发布

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.

3条回答
地球回转人心会变
2楼-- · 2019-01-15 21:10

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

查看更多
劳资没心,怎么记你
3楼-- · 2019-01-15 21:15

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

查看更多
走好不送
4楼-- · 2019-01-15 21:33

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.
查看更多
登录 后发表回答