我想构建自定义ImageSpan,在获取数据的开头设置默认图片,并在获取完成后加载图片。
代码示例:
public class CustomImageSpan extends ImageSpan {
private Drawable mDrawable;
@Override
public Drawable getDrawable() {
if (mDrawable == null) {
mDrawable = defaultDrawable;
Futures.addCallback(
FetchImage.submit(
new FutureCallback<Image>() {
@Override
public void onSuccess(Image result) {
Bitmap bitmap = result.getBitmap();
mDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
//!Rerender span with new bitmap.
}
}, mExecutor);
}
return mDrawable;
}
如何通知span加载已完成,是时候获取新位图而不是默认值?
答案 0 :(得分:-1)
您可以尝试使用处理程序在当前任务完成后继续执行下一个任务
Handler xHandler=new Handler(){
@Override
public void handleMessage(Message message){
switch (message.what){
case SOME_OPERATION:
getImage(); //the method you are using
break;
}
}
};
在单独的线程中运行句柄,如下所示
@Override
public void run() {
xHandler.sendMessage(Message.obtain(xHandler, SOME_OPERATION));
}