• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Downloading JSON information and displaying it in a listview

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

So I'm trying to achieve the very simple task of, as the title suggests, downloading some JSON data then just putting it in a ListView, however I just can't seem to make it work.

I am trying to download the data from here: http://www.webfleetsystems.co.uk/wbfleet/defects/getdefectlist.ashx

I've been looking through the documentation for Asynctask and things like that for a while but somehow I just still can't manage to achieve this simple task.

Here is my code for the class which downloads the information:



and the code for the class which is supposed to display the listview:



How do I correctly bind the data I downloaded to the listview to make it display the information?

I know there's probably tons of things I'm doing wrong but if someone could help me out I'd be really grateful. I know this is probably a noob question but I currently suck at android development.

edit: I forgot to add the code for the class which downloads the JSON data so here it is:

 
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There were quite a few issues that I found.

First the object you are getting back is a JSONArray not a JSONObject.

Then you initializing your String[] to 0. Which means you're going to go out of bounds every time you add something to it.
This is a good place to learn about Arrays https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Then to answer your question. In onPostExecute you need to add the items to your list then notify your adapter that items have been added.

I would probably use RxObservable instead of AsyncTasks.
RxJava
RxAndroid


Here's a working example. Its uses Butterknife.
Its not perfect but its a start.
 
Joshua Harris
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jules Aglo wrote:There were quite a few issues that I found.

First the object you are getting back is a JSONArray not a JSONObject.

Then you initializing your String[] to 0. Which means you're going to go out of bounds every time you add something to it.
This is a good place to learn about Arrays https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Then to answer your question. In onPostExecute you need to add the items to your list then notify your adapter that items have been added.

I would probably use RxObservable instead of AsyncTasks.
RxJava
RxAndroid


Here's a working example. Its uses Butterknife.
Its not perfect but its a start.



thanks for that, that reply was really helpful. Managed to get it working in the end.
 
reply
    Bookmark Topic Watch Topic
  • New Topic