gpt4 book ai didi

android - 在 Android 的 ListView 中滚动时 Listitems 改变位置

转载 作者:行者123 更新时间:2023-11-30 00:18:56 25 4
gpt4 key购买 nike

<分区>

我是 Android 的新手,我正在使用包含图像和一些文本的 customlistitems 开发一个 ListView,当我向上滚动时我发现了一个问题/在 ListView 下方,列表项的位置正在改变。那么有人可以帮助我吗?我在这里发布我的适配器以供您引用。希望你能帮我弄清楚。

OfferAdapter

public class OfferAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<Offer> OfferList;


public OfferAdapter(Context c, ArrayList<Offer> OfferList) {
mContext = c;
this.OfferList = OfferList;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return OfferList.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

if (convertView == null) {

grid = new View(mContext);
grid = inflater.inflate(R.layout.raw_offer, null);
TextView tv_ofr_hdr = (TextView) grid.findViewById(R.id.tv_ofr_hdr);
ImageView iv_pic = (ImageView) grid.findViewById(R.id.iv_pic);
TextView tv_ofr_desc = (TextView) grid.findViewById(R.id.tv_ofr_desc);
TextView tv_date = (TextView) grid.findViewById(R.id.tv_date);
tv_ofr_desc.setText(OfferList.get(position).getDescription());
tv_ofr_hdr.setText(OfferList.get(position).getHeadline());
Date from = new Date();
Date to = new Date();
SimpleDateFormat input = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat output = new SimpleDateFormat("dd/MM/yyyy");
try {
from = input.parse(OfferList.get(position).getStart_date());
to = input.parse(OfferList.get(position).getEnd_date()); // parse input

} catch (ParseException e) {
e.printStackTrace();
}

tv_date.setText(output.format(from) + " TO " + output.format(to));

Picasso.with(mContext)
.load(OfferList.get(position).getPhoto().replaceAll(" ", "%20"))
.placeholder(R.drawable.ic_no_img)
.error(R.drawable.ic_no_img)
.into(iv_pic);
} else {
grid = (View) convertView;
}

return grid;
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com