2013-07-20 31 views
1

我想在數據加載時顯示旋轉刷新,但得到此異常。我正在使用異步任務進行處理。請指導如何正確添加進度對話框以賦予紡紗效果。任何幫助將不勝感激。在Android應用程序窗口小部件中添加進度對話框時出現錯誤令牌異常

我的插件提供者類的onUpdate()方法

public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
      int[] appWidgetIds) { 

//--- 
     mProgressDialog = new ProgressDialog(context); 
     mProgressDialog.setIndeterminate(false); 
     mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
     try { 
      fetchTask.execute().get(); 
     } catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (ExecutionException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    mContext = context; 
} 

protected void onPreExecute(){ 
      mProgressDialog.show(); 
      //updateViews.setViewVisibility(R.id.refresh, View.GONE); 
      //updateViews.setViewVisibility(R.id.progress, View.VISIBLE); 
     } 

    protected Store doInBackground(URL... arg0) { 
//my stuff 
} 

protected void onPostExecute(Store storeObj) { 

      mProgressDialog.dismiss(); 
      //updateViews.setViewVisibility(R.id.progress, View.GONE); 
      //updateViews.setViewVisibility(R.id.refresh, View.VISIBLE); 


      pushWidgetUpdate(mContext,updateViews); 
     } 

我的XML

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"> 

    <ImageButton 
     android:id="@+id/refresh" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical|center_horizontal" 
     android:layout_marginLeft="25dp" 
     android:layout_marginRight="20dp" 
     android:background="#0079C1" 
     android:src="@drawable/navigation_refresh" 
     android:visibility="visible" /> 

    <ProgressBar 
     android:id="@+id/progress" 
     android:indeterminate="true" 
     style="?android:attr/progressBarStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:visibility="gone" /> 
</RelativeLayout> 

回答

0

明白了校正。我有不正確的寬度,按鈕和進度欄的高度,糾正了這一點。另外,做了foll。改變代碼..這裏是正確的。 onUpdate無法完成。

protected void onPreExecute(){ 

      updateViews.setViewVisibility(R.id.refresh, View.GONE); 
      updateViews.setViewVisibility(R.id.progress, View.VISIBLE); 
      pushWidgetUpdate(mContext,updateViews); 
     } 

protected void onPostExecute(Store storeObj) { 

      //my stuff 

      updateViews.setViewVisibility(R.id.progress, View.GONE); 
      updateViews.setViewVisibility(R.id.refresh, View.VISIBLE);   

      pushWidgetUpdate(mContext,updateViews); 
     } 



//My Layout file 
    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent"> 

     <ImageButton 
      android:id="@+id/refresh" 
      android:layout_width="70dp" 
      android:layout_height="80dp"    
      android:layout_marginLeft="25dp" 
      android:layout_marginRight="20dp" 
      android:background="#0079C1" 
      android:src="@drawable/navigation_refresh" 
      android:visibility="visible" /> 

     <ProgressBar 
      android:id="@+id/progress" 
      android:indeterminate="true" 
      style="?android:attr/progressBarStyle" 
      android:layout_width="70dp" 
      android:layout_height="80dp" 
      android:layout_margin="10dp" 
      android:indeterminateBehavior="cycle" 
      android:visibility="gone" /> 
    </RelativeLayout> 
相關問題