Problema con BaseAdapter
Domanda
HI, Ho esteso BaseAdapter, la mia dimensione della lista è di 20, ma è solo mostrando 7 record, dopo il record di 7 sta mostrando di nuovo da 0.
public class ContactsAdapter estende BaseAdapter { Elementi elenco privato; Contesto privato 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;
}
}
Si prega di aiuto
Soluzione
Visualizzazioni vengono riutilizzati, così si dovrebbe mettere tv_name.setText(t.getFirstName());
dopo il blocco 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());
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow