1
  1. 我展示里面progressdialog我旋转的动画与此代码

ProgressDialog pDialog = ProgressDialog.show(getActivity(),NULL,NULL,真之前执行的AsyncTask ,假); pDialog.setContentView(R.layout.loading);如何实现旋转的动画ProgressDialog用的AsyncTask

这是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> 
  • 然后我EXCUTE我的AsyncTask。当asynctask doInbackground我ProgressDialog的问题是不显示动画。

  • 经过asynctask onPostExecute我的ProgressDialog是启动动画。

  • 为什么在doInbackground我的ProgressDialog不显示动画?

    如何解决?

    我想在执行asynctask之前在对话框中显示旋转动画,并在asynctask执行结束后隐藏对话框。

    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) { 
        } 
    } 
    

    当MyTask doInBackground的progressdialog不旋转(doInBackground使用时间约5秒)。 但onPostExecute完成后它又开始旋转。 我测试它的禁令“pDialog.hide();”在onPostExcute;

    +0

    请张贴的完整代码 – 2014-09-10 10:28:44

    +0

    向我们展示你的异步任务,请 – 2014-09-10 10:31:33

    +0

    你不能在doInBackground方法UI交互。 – Aniruddha 2014-09-10 10:33:20

    回答

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