0

I'm having some trouble with a ViewPager...

So I have a JsonObject (World Weather Online) which has an array "Weather" containing 7 childs object, and each of these Object contain a single array "Hourly" which has 8 childs object.

I would like to use the array "weather" and its 7 childs to determine the number a swipeable screens and display the date in the PageTitleStrip. And each of these swipeable views would contain a ListView with the 8 objects contained in the "Hourly" array as items.

I do it properly with dummy datas using xml arrays in values but obvioulsy having trouble with a JsonObject.

Can anyone help and explain to me how I could achieve it?

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Makoto
  • 1,455
  • 4
  • 13
  • 17

1 Answers1

0

The first one, you should parse that json array to weather model which has hourly datas in each of them array.

In your PagerAdapter you should override getCount that return size of model array.

Again in your PagerAdapter you also should override getItem that returns WeatherFragment. You need to pass one of the weather model to your WeatherFragment. Please check Bundle usage with Fragments.

In your WeatherFragment you need to have a ArrayAdapter to fill ListView with your hourly datas.

Your Weather Array need to be singleton.

Good luck there.

Emre Aktürk
  • 3,306
  • 2
  • 18
  • 30
  • Thx for explaining the steps to follow!! So I should create a Weather Model then but should I put my AsyncTask in it too? – Makoto Nov 11 '14 at 09:38
  • For some reason the Objects are empty... From where to call the AsyncTask execute()?? I did in the PagerAdapter constructor but obviously it doesn't work – Makoto Nov 12 '14 at 05:55
  • The first one you need to get data and parse it from JSON to Object in activity with AsyncTask. Whenever your AsyncTask completed (i mean onResult) you can pass your Weather Array Model to PagerAdapter within constructor. So you can override that default constructor. – Emre Aktürk Nov 12 '14 at 07:37
  • Finally got it to work completely! I cannot vote here yet (as you need minimum "reputation") but thx a lot for your help! – Makoto Nov 12 '14 at 21:41