BaseAdapter 问题
你好, 我已经扩展了BaseAdapter,我的列表大小是20,但它只显示7条记录,在第7条记录之后,它再次从0开始显示。
public class ContactsAdapter extends 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;
}
帮忙
请
HI,
i have extended BaseAdapter, my size of the list is 20,but it is showing only 7 records, after the 7th record it is showing again from 0.
public class ContactsAdapter extends BaseAdapter {
private List elements;
private Context 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;
}
}
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
视图会被重用,因此您应该将
tv_name.setText(t.getFirstName());
放在 if-else 块之后:Views are reused, so you should put
tv_name.setText(t.getFirstName());
after the if-else block: