这是一个小小的XML动画,我试图在应用程序从服务器获取JSON时关闭它。它需要大约2秒钟来获取所有的数据,所以我试图展示一些加载动画。来自异步任务的Android更新视图
我遇到的问题是图像不会改变,直到一切完成并onPostExecute()熄灭。
我需要传递一个视图到AsyncTask中吗?还是其他的东西?
这个AsyncTask完成后的最后一件事。如果您再次运行它,它会运行平稳。
XML
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/loadingtext1" android:duration="100" />
<item android:drawable="@drawable/loadingtext2" android:duration="100" />
<item android:drawable="@drawable/loadingtext3" android:duration="100" />
<item android:drawable="@drawable/loadingtext4" android:duration="100" />
</animation-list>
代码
private class LOGMEIN extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
CRY.CInit(DI, DU, DP);
publishProgress(0);
while(data != "whatineed"){
try {
Thread.sleep(450);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
completecheck = 1;
return "complete";
}
@Override
protected void onPreExecute() {
LOADINGTEXT.setBackgroundResource(R.drawable.animation);
AnimationDrawable LT = (AnimationDrawable) LOADINGTEXT.getBackground();
LT.start();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result.contentEquals("complete") == true) {
domorework();
} else {
finish();
}
}
}
我还没有想出来,现在 – Xjasz