Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent next fragment (tab) from preload with ViewPager

I am developing an app in Android using Fragments. I have this three tabs:

User app screenshot

I know that is not possible to prevent the load of one fragment on each side (previous and next) as far as the minimum value of setOffScreenPageLimit() is 1 but does it mean that if I want to show a ProgressDialog on the onPreExecute method of an AsyncTask running within Descargas Fragment this will cause that when I nav to the Capturador that ProgressDialog will be necessarily loaded? If yes I have no idea of how to let the user know that I am downloading the packages (that's what Descargas does, to parse some XML).

Thanks in advance ;)

like image 563
Keyser Sozé Avatar asked Aug 05 '12 18:08

Keyser Sozé


1 Answers

Embed a ProgressBar on the Descargas fragment. Or overlay an indeterminate progressbar over the center of the fragment while it loads.

Dialogs are really part of the activity, it wouldn't make sense that it's only applicable to one of the pages.

At the end of the day though if you must insist on using dialogs, you can implement an onPageChangeListener

viewPager.setOnPageChangeListener(OnPageChangeListener);

And you can pull up the appropriate dialog when the designated fragment is selected and the opposite when you navigate away.

like image 167
Pork 'n' Bunny Avatar answered Nov 16 '22 22:11

Pork 'n' Bunny