好吧,我用這個項目作爲起點,以我的項目: https://github.com/thest1/LazyList/懶圖像加載到ListView控件
相反,他LazyAdapter我用一個,我提出,以下內容:
public class CardAdapter extends ArrayAdapter<Card> {
private Card[] cards;
private Context context;
private LayoutInflater mInflater;
public ImageLoader imageLoader;
public CardAdapter (Context context, int textViewResourcesId, Card[] cards)
{
super(context, textViewResourcesId, cards);
this.cards = cards;
this.context = context;
mInflater = LayoutInflater.from(context);
}
private static class ViewHolder {
public ImageView iconView;
public TextView nameTextView;
public TextView descText;
public TextView manaText;
public TextView atkdef;
public TextView edicao;
public TextView tipo;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listrow, parent, false);
TextView nameTextView = (TextView) convertView
.findViewById(R.id.Nome);
TextView descText = (TextView) convertView
.findViewById(R.id.descricao);
TextView manaText = (TextView) convertView
.findViewById(R.id.mana);
TextView atkdef = (TextView) convertView
.findViewById(R.id.atkdef);
TextView edicao = (TextView) convertView
.findViewById(R.id.edicao);
TextView tipo = (TextView) convertView
.findViewById(R.id.tipo);
ImageView iconView = (ImageView) convertView
.findViewById(R.id.imageView1);
holder = new ViewHolder();
holder.nameTextView = nameTextView;
holder.descText = descText;
holder.manaText = manaText;
holder.atkdef = atkdef;
holder.edicao = edicao;
holder.tipo = tipo;
holder.iconView = iconView;
holder.iconView.setTag(cards[position].URL);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.nameTextView.setText(cards[position].name); holder.descText.setText(setSpanOnText(cards[position].descricao),BufferType.SPANNABLE);
holder.manaText.setText(setSpanOnManaText(cards[position].mana), BufferType.SPANNABLE);
if (cards[position].tipo.toLowerCase().contains("creature"))
holder.atkdef.setText(cards[position].power + "/" + cards[position].toughness);
else
holder.atkdef.setText("");
holder.edicao.setText("Edition: " + cards[position].edicao);
holder.tipo.setText(cards[position].tipo);
holder.iconView.setTag(cards[position].URL);
imageLoader.DisplayImage(cards[position].URL, holder.iconView);
return convertView;
}
}
這是工作直到我添加了「imageLoader.DisplayImage(cards [position] .URL,holder.iconView);」這是懶惰的負載部分,當我嘗試訪問列表視圖時,它開始崩潰,有人在想什麼?我沒有改變在ImageLoader/FileCache/MemoryCache/Utils從另一個項目...
謝謝你的建議!
它開始崩潰,然後把你的Logcat? – 2012-03-07 09:58:33
發佈您的logcat錯誤也 – 2012-03-07 09:58:35
請把你的錯誤日誌在這裏 – chengbo 2012-03-07 09:58:46