1
  1. I show my rotate animation inside progressdialog before execute asynctask with this code

ProgressDialog pDialog = ProgressDialog.show(getActivity(), null, null, true, false); pDialog.setContentView(R.layout.loading);

this is R.layout.loading xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ln_loadingcontainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#00000000">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Large"
        android:layout_gravity="center"/>

    <TextView
        android:id="@+id/tv_loading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Loading..."
        android:textSize="24dp"
        android:textColor="#ffffff"
        android:layout_marginTop="5dp"
        android:layout_gravity="center"/>
</LinearLayout>
  1. Then i excute my asynctask. The problem when asynctask doInbackground my ProgressDialog is not display animation.

  2. After asynctask onPostExecute my ProgressDialog is start animation.

Why on doInbackground my ProgressDialog not display animation?

How to solve it?

I want to display rotate animation inside dialog before excute asynctask and hide dialog after asynctask excute finish.

EDIT

1.global variable of ProgressDialog

private ProgressDialog pDiaalog;

2.in oncreate of activity

gv_table.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        progressDialog = ProgressDialog.show(getActivity(), null, null, true, true);
        progressDialog.setContentView(R.layout.loading);

        MyTask t = new MyTask();
        t.execute();
    }
});

3.MyTask

private class MyTaskextends AsyncTask<String, Void, String>{

    public MyTask(){
    }

    @Override
    protected String doInBackground(String... params) {
        RunExecute();
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        if (pDialog != null) {
            if (pDialog.isShowing())
                pDialog.hide();
        }
    }

    @Override
    protected void onPreExecute() {
        if(IsShowProgress) {
            if (pDialog != null)
                pDialog.show();
        }

        super.onPreExecute();
    }

    @Override
    protected void onProgressUpdate(Void... values) {
    }
}

When MyTask doInBackground the progressdialog not spinning (doInBackground usage time about 5 sec). But after onPostExecute finish It's start spinning again. I test it's by ban "pDialog.hide();" in onPostExcute;

user2955394
  • 1,063
  • 4
  • 17
  • 34

1 Answers1

0
ProgressDialog pDialog;
onPreExecure()
pDialog = ProgressDialog.show(MainActivity.this, null, null, true, false); 
        pDialog.setContentView(R.layout.loading);
onPostExecute()
if(pDialog.isShowing())
{
    pDialog.dismiss();
}