how to show progress bar(circle) in an activity having a listview before loading the listview with data

后端 未结 12 2476
忘掉有多难
忘掉有多难 2020-11-28 00:18

I have a ListView in my second activity.OnItemClick of it I called a webservice and trying to fetch data. And after that I am moving to third activ

12条回答
  •  鱼传尺愫
    2020-11-28 01:02

    Please use the sample at tutorialspoint.com. The whole implementation only needs a few lines of code without changing your xml file. Hope this helps.

    STEP 1: Import library

    import android.app.ProgressDialog;
    

    STEP 2: Declare ProgressDialog global variable

    ProgressDialog loading = null;
    

    STEP 3: Start new ProgressDialog and use the following properties (please be informed that this sample only covers the basic circle loading bar without the real time progress status).

    loading = new ProgressDialog(v.getContext());
    loading.setCancelable(true);
    loading.setMessage(Constant.Message.AuthenticatingUser);
    loading.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    

    STEP 4: If you are using AsyncTasks, you can start showing the dialog in onPreExecute method. Otherwise, just place the code in the beginning of your button onClick event.

    loading.show();
    

    STEP 5: If you are using AsyncTasks, you can close the progress dialog by placing the code in onPostExecute method. Otherwise, just place the code before closing your button onClick event.

    loading.dismiss();
    

    Tested it with my Nexus 5 android v4.0.3. Good luck!

提交回复
热议问题