0

私はGridviewいくつかのとで私を埋めようTextViewsとしていImageviewsます。成功しましたが、グリッドを下にスクロールすると、画像の位置が変わります。同じ問題に関連する他の質問を読みました。この1つの質問のように、しかしそれは私を助けませんでした.

アダプタ

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;
  }
}
4

1 に答える 1

-1

findViewByIdのときに呼び出す必要がありますconvertView == null

if (convertView == null) {
    convertView = l_Inflater.inflate(R.layout.activity_gridview_items, parent, false);
    holder = new ViewHolder();

    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);

    convertView.setTag(holder);
} else {
    holder = (ViewHolder) convertView.getTag();
}       
于 2013-03-24T12:25:35.463 に答える