7

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 ;)

Keyser Sozé
  • 739
  • 1
  • 9
  • 16
  • 1
    This question is worded great. I'm facing a similar challenge like this, where I have to show `Dialogs` in different `Fragments` but I can't because they overlap each other. – tolgap Aug 05 '12 at 18:52
  • Let's then hope somebody will help us. I have to admit I am a bit or more than a bit confused with Fragments but I don't know how to get this issue fixed. – Keyser Sozé Aug 05 '12 at 19:58
  • It's pretty stupid that `setOffScreenPageLimit()` always defaults to 1. – tolgap Aug 05 '12 at 20:42
  • Not related to question, but the Android Design Guidelines say to always put your Settings button in the overflow menu. – Steven Schoen Aug 05 '12 at 23:22

1 Answers1

4

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.

Pork 'n' Bunny
  • 6,740
  • 5
  • 25
  • 32
  • Thank you for your answer. Then I'll try to do something consistent and in accordance to the good habits of programming considering I am just learning. I guess the good way would be then to control the Graphic events like Dialogs or Toast in the main Activity not in the Fragments. I'd appreciate if somebody can give me ideas. I don't want any of you to do my work but just hints or instructions. – Keyser Sozé Aug 05 '12 at 22:36
  • Answering to myself and thanks to Pork I finally implemented an indeterminated ProgresBar defined in the Layout which I hide with ProgressBar.setVisibility(View.GONE) if the Descargas fragment successfully retrieved the packages I want and so on. I hope it's not a shabby solution because with my knowledge, which is not that advanced, I can't even start to implement the OnPageChangeListener option. – Keyser Sozé Aug 06 '12 at 00:15
  • That sounds perfect Keyser! You can certainly use dialogs from a fragment, but a fragment within a viewpager is kind of tricky. You have to be mindful that the dialog is really meant to prevent the user from taking any other actions. But if they have other things they can do within the activity while waiting, then it's best not to use a dialog. For me, that means progressdialog is a quick hack that usually shouldn't make it into most peoples final solutions. You can drive dialogs from a fragment, that's fine, just be aware that the user only really knows/cares about the activity. – Pork 'n' Bunny Aug 06 '12 at 04:18
  • You are absolutely right. It doesn't make sense that I block the UI with a ProgressDialog when the user can actually perform other actions on the app while Descargas is doing its work. Thank you very much because you didn't just write me a slice of code and that's all, you made me see the unlogic of my previous procedure. – Keyser Sozé Aug 06 '12 at 09:43