0
調用的問題的AsyncTask onProgressUpdate反覆
的AsyncTask onProgressUpdate連續多次調用並不會停止。 onProgressUpdate被連續調用+1000次。
- publishProgress()被調用3次。 (如預期)
- onPostExecute被執行,但onProgressUpdate繼續被調用。
- 我在應用程序中以類似的方式應用了另一個AsynTask,它工作得很好。
的特點
我,直到它停止在選定的項目,它們通過了項目的網格。選擇通過改變RelativeLayout的背景來顯示。
簡化的代碼
public class test extends Activity {
GridView gridView;
...
private class Async_wordletNewCharacter extends AsyncTask<String, Integer, Boolean> {
RelativeLayout gridItem;
RelativeLayout itemSel;
Drawable goldDrawable = getResources().getDrawable(R.drawable.sh_circle_gold);
public Async_wordletNewCharacter(String param) {super();}
@Override
protected Boolean doInBackground(String... params) {
try {
ArrayList<Integer> positionList = new ArrayList<>(Arrays.asList(1, 2, 3));
for (int i = 0; i < positionList.size(); i++) {
int position = positionList.get(i);
gridItem = (RelativeLayout) gridView.getChildAt(position);
itemSel = (RelativeLayout) gridItem.findViewById(R.id.item_selector);
publishProgress(0); // Circle the selected item
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return true;
}
@Override
protected void onProgressUpdate(Integer... values) {
super.publishProgress(values);
itemSel.setBackground(goldDrawable);
}
protected void onPostExecute(Boolean a) {
Log.d(LOG, "async_wait : onPostExecute");
}
}
}
任何幫助將不勝感激。提前致謝!
非常感謝Rajesh!男人,多麼愚蠢的錯誤哈哈 – Han 2015-04-05 09:42:33