Home > Mobile >  Android fragments with network request loading recycler
Android fragments with network request loading recycler

Time:09-17

Met a very wonderful question,,,
I loaded the four fragments in a viewpager

Then in the second fragment wrote a recyclerview, and use okhttp parsing json after loading recyclerview

Then it is strange that every time I open the app, switch directly to the second fragment (viewpager initial shows the first fragments), recyclerview no load

Every time to switch to the fourth fragments

Then switch to the second

Recyclerview it would appear,
Want to for a long time can't imagine what it is, if I don't switch to the fourth fragments, in front of the viewpager 3 no matter how to switch pages, page 2 of recyclerview doesn't load

CodePudding user response:

Do you have a question, and that in itself is your networking within the child thread, adapter binding inside the UI thread, you should be at the back of the networking operation notice adapter updates, add the try on the end of the for loop adapter. The notifyDataSetChanged ();

CodePudding user response:

You put initItem code in the onViewCreated, at that time the view to refresh

CodePudding user response:

refer to the second floor keyboard 113 dancers response:
onViewCreated you put initItem code, then the view to the refresh

Excuse me, how to change better, put is inititem in the MainActivity?

CodePudding user response:

reference kenpeitai reply: 3/f
Quote: refer to the second floor keyboard 113 dancers response:
you put initItem code in the onViewCreated, at that time the view to the refresh

Excuse me, how to change better, put is inititem in the MainActivity?

I said, in fragments onViewCreated function
  • Related