gpt4 book ai didi

android - BaseAdapter 的问题

转载 作者:行者123 更新时间:2023-11-30 04:48:19 25 4
gpt4 key购买 nike

嗨,我已经扩展了 BaseAdapter,我的列表大小是 20,但它只显示了 7 条记录,在第 7 条记录之后它又从 0 开始显示。

公共(public)类 ContactsAdapter 扩展 BaseAdapter { 私有(private)列表元素; 私有(private)上下文 c;

public ContactsAdapter(Context c, List<ContactBean> Tweets) {
this.elements = Tweets;
this.c = c; }

public int getCount() {
return elements.size(); }

public Object getItem(int position) {
System.out.println(":: ::"+position);
System.out.println("Printing Postions ::"+elements.get(position));
return elements.get(position); }

public long getItemId(int id) {
return id; }

public void Remove(int id) { notifyDataSetChanged(); }

public View getView(int position, View convertView, ViewGroup parent) {

LinearLayout rowLayout;
ContactBean t = elements.get(position);

if (convertView == null) {
rowLayout = (LinearLayout) LayoutInflater.from(c).inflate(
R.layout.list_view, parent, false);
TextView tv_name = (TextView) rowLayout.findViewById(R.id.txt_contacts_name);
tv_name.setText(t.getFirstName());
} else {
rowLayout = (LinearLayout) convertView;
}
return rowLayout;
}

请帮忙

最佳答案

View 被重用,所以你应该在 if-else block 之后放置 tv_name.setText(t.getFirstName());:

if (convertView == null) {
rowLayout = (LinearLayout) LayoutInflater.from(c).inflate(R.layout.list_view, parent, false);
} else {
rowLayout = (LinearLayout) convertView;
}

TextView tv_name = (TextView) rowLayout.findViewById(R.id.txt_contacts_name);
tv_name.setText(t.getFirstName());

关于android - BaseAdapter 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4252956/

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