0

I have read many solutions here to show a progress dialog on switching tabs as some of the tabs fetching data from server takes time in between that period i need to show progress dialog, do suggest where to put the code to accomplish my task

Vivek Singh
  • 1,201
  • 3
  • 17
  • 39
  • Are you using fragments? What have you tried that isn't working? – Phix Dec 17 '12 at 18:36
  • i have tried asynctask and also requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); getParent().setProgressBarIndeterminateVisibility(true); but this also not working – Vivek Singh Dec 18 '12 at 05:55

1 Answers1

0

Initiate an Async which does the fetching data in the background and manages the progress dialog (or even progress layout which might be better) in the onprogressupdate method. If you subclass this it will be fairly easy to implement. Here's a link.

Add this

private class myAsyncTaskClass extends AsyncTask{

    @Override
    protected void onProgressUpdate(Object... values) {
        // TODO Add updates to your progress dialog here. 
        super.onProgressUpdate(values);
    }

    @Override
    protected Object doInBackground(Object... params) {
        // TODO Add your fetching data here
                    //Use publish progress to call the onProgress update passing whatever you want. 
                    publishProgress(values);

        return null;
    }}
AndroidPenguin
  • 3,445
  • 2
  • 21
  • 42
  • i tried Async Task earlier but its not working the way i want, i want sonner i switch my tab it show me progress dialog till may activity fetch data from server – Vivek Singh Dec 18 '12 at 05:53
  • Add showing the progress dialog to preexecute. That'll do that first, then move on. Either you can make it indeterminate or start it at zero and then callbacks from your do in background will update it – AndroidPenguin Dec 18 '12 at 13:17
  • Depending on the frequency of how likely the person is to switch tabs, you might wish to create a background thread and load it before the person switches rendering the process more smooth – AndroidPenguin Dec 18 '12 at 13:19
  • let me clear my problem, i have a spinner in which i'm binding data from server i have used asynctask from which i am getting data from server for spinner but the spinner is already created at Oncreate() , hope you are getting what i'm trying to explain – Vivek Singh Dec 20 '12 at 11:56