问题
AsyncTask onProgressUpdate连续多次调用,不会停止。 onProgressUpdate连续每秒调用+1000次。
功能
我有一个项目网格,直到它停在所选项目。通过更改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");
}
}
}
非常感谢任何帮助。在此先感谢!
答案 0 :(得分:2)
super.publishProgress(values);
是罪魁祸首。显然,你的意思是super.onProgressUpdate(values);
不是吗?