嗨,我已经扩展了BaseAdapter,我的列表大小是20,但它只显示了7条记录,在第7条记录之后,它又从0开始显示。
公共类ContactsAdapter扩展了BaseAdapter {私有列表元素;私有上下文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;
}}
请帮帮忙
发布于 2010-11-23 13:09:51
视图被重用,因此您应该将tv_name.setText(t.getFirstName());放在if-else块之后:
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());https://stackoverflow.com/questions/4252956
复制相似问题