[英]onPostExecute clash when using AsyncTask - android
我不明白这里发生了什么。 ide
onPostExecute(Bitmap)' in 'Anonymous class derived from android.os.AsyncTask' clashes with 'onPostExecute(Result)' in 'android.os.AsyncTask'; attempting to use incompatible return type
抛出此消息, onPostExecute(Bitmap)' in 'Anonymous class derived from android.os.AsyncTask' clashes with 'onPostExecute(Result)' in 'android.os.AsyncTask'; attempting to use incompatible return type
onPostExecute(Bitmap)' in 'Anonymous class derived from android.os.AsyncTask' clashes with 'onPostExecute(Result)' in 'android.os.AsyncTask'; attempting to use incompatible return type
:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final View[] v = {convertView};
final Bitmap[] mBitmap = new Bitmap[1];
final Object that = this.resources;
View view = new AsyncTask<Void, Void, Bitmap>() {
protected Bitmap doInBackground(Void... args) {
try {
mBitmap[0] = drawableFromUrl(activity.getString(R.string.test_url));
} catch (IOException e) {
e.printStackTrace();
}
return mBitmap[0];
}
@Override
protected View onPostExecute(Bitmap mBitmap) {
Drawable d = new BitmapDrawable((Resources) that, mBitmap);
final Feed item = feed_items.get(position);
if (v[0] == null) {
LayoutInflater vi =
(LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v[0] = vi.inflate(R.layout.grid_item, null);
}
if (item != null) {
v[0].findViewById(R.id.v1).setBackground(d);
v[0].findViewById(R.id.v2).setBackground(d);
}
return v[0];
}
}.execute((Void) null);
return view;
}
我假设您在自定义adapater中使用getView()。
但是您不能从onPostExecute()返回,因此请尝试立即扩大视图。
设置AsyncTask以下载BPM并更新视图,但是即使数据还不存在,也可以从getView()返回它。 一旦异步完成,它将在那里。
public View getView(final int position, View convertView, ViewGroup parent) {
View v1 = convertView;
final Bitmap[] mBitmap = new Bitmap[1];
final Object that = this.resources;
final View v;
if (v1 == null) {
LayoutInflater vi =
(LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.grid_item, null);
}
else {
v = v1;
}
new AsyncTask<Void, Void, Bitmap>() {
protected Bitmap doInBackground(Void... args) {
try {
mBitmap[0] = drawableFromUrl(activity.getString(R.string.test_url));
} catch (IOException e) {
e.printStackTrace();
}
return mBitmap[0];
}
@Override
protected void onPostExecute(Bitmap mBitmap) {
Drawable d = new BitmapDrawable((Resources) that, mBitmap);
final Feed item = feed_items.get(position);
v.findViewById(R.id.v1).setBackground(d);
v.findViewById(R.id.v2).setBackground(d);
}
}.execute((Void) null);
return v;
}
onPostExecute的返回类型应该为空。
请参阅: http : //developer.android.com/reference/android/os/AsyncTask.html#onPostExecute%28Result%29
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.