我想加載圖像的ImageButton進入適配器一個ImageButton
,這有時不工作...我有4項,有時候,按鈕圖像只是加載2適配器而不是4次。始終只在第一次創建適配器的......之後屏幕旋轉左右,一切正常。但在第一顯示器上,它不能正常工作...畢加索 - 加載圖像到適配器
具有4行的適配器調用2次準備並加載僅在第一個創造兩次......
以下是我的適配器的getView
:
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
if (convertView == null)
convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_link, parent, false);
convertView.setTag(R.id.tag_pos, position);
ImageView iconRow = ViewHolder.get(convertView, R.id.icon);
final ImageButton btOpen = ViewHolder.get(convertView, R.id.btOpen);
// this NEVER fails
PicassoTools.getPicasso().load(item.getIconResId()).into(iconRow);
// this sometimes (at the first start) does not work reliable
PicassoTools.getPicasso().load(isAutoLinked ? R.drawable.linked : R.drawable.unlinked).into(new Target()
{
@Override
public void onPrepareLoad(Drawable d)
{
L.d(this, "BUTTON PREPARE");
}
@Override
public void onBitmapLoaded(Bitmap b, LoadedFrom loadedFrom)
{
L.d(this, "BUTTON LOADED");
btLink.setImageBitmap(b);
}
@Override
public void onBitmapFailed(Drawable d)
{
L.d(this, "BUTTON FAILED");
btLink.setImageBitmap(null);
}
});
return convertView;
}
我PicassoTools功能(我在這個班,一些額外的功能):
public static Picasso getPicasso()
{
if (picasso == null)
picasso = new Picasso.Builder(MainApp.getAppContext()).memoryCache(getCache()).build();
return picasso;
}
你能請張貼滿適配器代碼,並在那裏你初始化btLink在getView( )? – 2014-11-03 09:00:01
你真的必須使用畢加索嗎?因爲我沒有使用畢加索我有一個很好的解決方案。 – Harry 2014-11-03 09:28:50
我有一個基於圖像的應用程序,因此(因爲我仍然得到一些OOM錯誤)試圖在可能到處使用緩存......反正已經給出的答案是解決方案......只是沒想到這個小細節了.. – prom85 2014-11-03 09:31:56