[英]ListView row ImageView issue
我有一個具有Imageview組件的listview行。 在getview()
方法中,我正在做一些檢查,根據它們,我使用setBackgroundResource()
方法更改了imageview
。
運行某些行時, imageview
組件彼此包含多個圖像,這是一個問題。
有什么我可以解決的問題嗎? (我為每行(位置)更改一次BackgroundResource
。
我看不到任何代碼,但我認為您應該使用ViewHolder。
例:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.sample, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(myElements.get(id));
holder.icon.setImageBitmap( mIcon1 );
return convertView;
}
static class ViewHolder {
TextView name;
ImageView icon;
}
如果這樣不能幫助異步加載圖像。 我會推薦畢加索。 http://square.github.io/picasso/
關於Nils
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.