android - Getting data (asynchronous) and populating ViewPager's fragments -


i have activity viewpager variable number of fragments (tabs).

upon start activity checks if associated (complex) data has been loaded. if hasn't shows progress bar view , starts asynctask fetches data. depending on data activity creates number of fragments (tabs) , gives each fragment sub set of data.

i hold references fragments (i know discouraged) , run sorts of problems when fragments gets reused - i'm giving data wrong instance of fragment.

so, there "android way" of solving problem?

i run sorts of problems when fragments gets reused

fragments don't reused in viewpager. not adapterview rows recycled. using fragmentpageradapter or fragmentstatepageradapter, fragment represents 1 , 1 page.

i re-instantiate viewpager each time (but fragments reused?)

ah. that's different problem.

the stock implementations of fragmentpageradapter , fragmentstatepageradapter make couple of assumptions:

  1. they in complete control on fragments, particularly in terms of running transactions add , remove them ui

  2. that fragments ever used 1 "logical" viewpager (iow, recreating viewpager configuration change fine, that' pretty it)

complicating matters these adapters store fragments under tags, , therefore if fragments still exist in tags, existing ones used, instead of new ones being created.

so, there "android way" of solving problem?

it's unclear question why need "re-instantiate viewpager". i'm assuming tied sort of refresh operation, or else forcing go through process described in second paragraph.

you give my arraypageradpater try, friendlier external agents mucking fragments. since control fragments' tags, can working right fragment -- rather caching them yourself, retrieve right 1 , manipulate it.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -