我設法找到解決的辦法是
public class YourViewsFactory implements RemoteViewsService.RemoteViewsFactory
{
Map<Integer, Boolean> flags = Collections.synchronizedMap(new HashMap<Integer, Boolean>());
Bitmap mBitmap;
Handler handler = new Handler(Looper.getMainLooper());
@Override
public RemoteViews getViewAt(final int position)
{
final RemoteViews row = new RemoteViews(ctxt.getPackageName(), R.layout.row);
flags.put(position, false);
handler.post(new Runnable()
{
@Override
public void run()
{
m_imgLoader.loadImage(YOUR_IMAGE_URL, new SimpleImageLoadingListener()
{
@Override
public void onLoadingStarted(String imageUri, View view)
{
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason)
{
flags.put(position, true);
}
@Override
public void onLoadingCancelled(String imageUri, View view)
{
flags.put(position, true);
}
@Override
public void onLoadingComplete(String arg0, View arg1, Bitmap bitmap)
{
mBitmap = bitmap;
flags.put(position, true);
}
});
}
});
while (!flags.get(position))
{
try
{
Thread.sleep(100);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
flags.put(position, false);
if (mBitmap != null)
{
row.setImageViewBitmap(R.id.ivPoster, mBitmap);
} else
{
row.setImageViewResource(R.id.ivPoster, R.drawable.cw);
}
mBitmap = null;
} // End of getViewAt override
} // End of class
這不是我的解決方案,但Vova Klyshevich可用here之一!
這是否仍然與最新版本的圖書館有關? 爲什麼不使用loadImageSync(...)? – grebulon
當列表中有大約20個元素時,滾動是不真實的慢。並在經過一些上下循環之後崩潰啓動器。 – anil
@ azerto00你能告訴我如何維護你的代碼中的緩存嗎? – Sangeetha