0
我想填充我的Gridview
與一些TextViews
和Imageviews
。我成功地做到了,但當我在網格中向下滾動時,圖像會改變它們的位置。我已經讀過一些與同一問題有關的其他問題;像這個question,但它沒有幫助我。在gridview中的圖像更改他們在android中的滾動位置
Aadapter
public class ItemListBaseAdapter extends BaseAdapter {
private static ArrayList<ItemDetails> itemDetailsrrayList;
private LayoutInflater l_Inflater;
private Context context;
// private OnClickListener listner;
public ItemListBaseAdapter(Context context, ArrayList<ItemDetails> results) {
itemDetailsrrayList = results;
l_Inflater = LayoutInflater.from(context);
this.context = context;
}
public int getCount() {
return itemDetailsrrayList.size();
}
public Object getItem(int position) {
return itemDetailsrrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.activity_gridview_items,
null);
holder = new ViewHolder();
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txt_itemName = (TextView) convertView
.findViewById(R.id.tv_item_title);
holder.txt_itemDescription = (TextView) convertView
.findViewById(R.id.tv_item_detail);
holder.txt_itemPrice = (TextView) convertView
.findViewById(R.id.tv_item_price);
holder.itemImage = (ImageView) convertView
.findViewById(R.id.iv_item_image);
holder.txt_itemName
.setText(itemDetailsrrayList.get(position).getName());
holder.txt_itemDescription.setText(itemDetailsrrayList.get(position)
.getItemDescription());
holder.txt_itemPrice.setText("Rs "
+ itemDetailsrrayList.get(position).getPrice());
holder.itemImage.setImageBitmap(itemDetailsrrayList.get(position)
.getImage());
return convertView;
}
static class ViewHolder {
TextView txt_itemName;
TextView txt_itemDescription;
TextView txt_itemPrice;
ImageView itemImage;
Button likeBtn;
Button addBtn;
}
}
我已經試過這種方法,結果相同 – 2013-03-24 12:28:14