Форум для тех, кто программирует под Android
Anonymous
Как эффективно загрузить тысячи данных в listview
Сообщение
Anonymous » 09 дек 2024, 21:06
У меня есть тысячи клиентов, которые нужно загрузить в пользовательский список с сервера. Но мне требуется больше времени, чтобы заполнить список. Я использую опцию поиска для поиска клиентов, поэтому мне нужно загрузить и отобразить всех клиентов за один раз. Я не могу отобразить его из локальной базы данных, потому что я могу редактировать данные по щелчку элемента в просмотре списка и сохранять их на сервере. Может ли кто-нибудь помочь мне эффективно загрузить настраиваемый список?
Код: Выделить всё
public class CustomersAdapter extends ArrayAdapter {
private ArrayList items;
private LayoutInflater vi;
private Item objItem;
ViewHolderSectionName holderSection;
ViewHolderName holderName;
public CustomersAdapter(Context context, ArrayList items) {
super(context, 0, items);
this.items = items;
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
objItem = items.get(position);
if (objItem.isSectionItem()) {
SectionHeadersModel si = (SectionHeadersModel) objItem;
if (convertView == null
|| !convertView.getTag().equals(holderSection)) {
convertView = vi.inflate(R.layout.alphabet_separator, null);
holderSection = new ViewHolderSectionName();
convertView.setTag(holderSection);
} else {
holderSection = (ViewHolderSectionName) convertView.getTag();
}
holderSection.section = (TextView) convertView
.findViewById(R.id.alphabet_letter);
holderSection.section.setText(si.getSectionString().toString());
} else {
CustomerListViewModel ei = (CustomerListViewModel) objItem;
if (convertView == null || !convertView.getTag().equals(holderName)) {
convertView = vi.inflate(R.layout.customer_list_item, null);
holderName = new ViewHolderName();
convertView.setTag(holderName);
} else {
holderName = (ViewHolderName) convertView.getTag();
}
holderName.name = (TextView) convertView
.findViewById(R.id.CustomerName);
holderName.email = (TextView) convertView
.findViewById(R.id.CustomerEmail);
holderName.phone = (TextView) convertView
.findViewById(R.id.CustomerPhone);
if (holderName.name != null)
holderName.name.setText(ei.getCustomerName());
holderName.email.setText(ei.getCustomerEmail());
holderName.phone.setText(ei.getCustomerPhone());
}
return convertView;
}
public static class ViewHolderName {
public TextView name;
public TextView email;
public TextView phone;
}
public static class ViewHolderSectionName {
public TextView section;
}
Подробнее здесь:
https://stackoverflow.com/questions/262 ... fficiently
1733767572
Anonymous
У меня есть тысячи клиентов, которые нужно загрузить в пользовательский список с сервера. Но мне требуется больше времени, чтобы заполнить список. Я использую опцию поиска для поиска клиентов, поэтому мне нужно загрузить и отобразить всех клиентов за один раз. Я не могу отобразить его из локальной базы данных, потому что я могу редактировать данные по щелчку элемента в просмотре списка и сохранять их на сервере. Может ли кто-нибудь помочь мне эффективно загрузить настраиваемый список? [code] public class CustomersAdapter extends ArrayAdapter { private ArrayList items; private LayoutInflater vi; private Item objItem; ViewHolderSectionName holderSection; ViewHolderName holderName; public CustomersAdapter(Context context, ArrayList items) { super(context, 0, items); this.items = items; vi = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(final int position, View convertView, ViewGroup parent) { objItem = items.get(position); if (objItem.isSectionItem()) { SectionHeadersModel si = (SectionHeadersModel) objItem; if (convertView == null || !convertView.getTag().equals(holderSection)) { convertView = vi.inflate(R.layout.alphabet_separator, null); holderSection = new ViewHolderSectionName(); convertView.setTag(holderSection); } else { holderSection = (ViewHolderSectionName) convertView.getTag(); } holderSection.section = (TextView) convertView .findViewById(R.id.alphabet_letter); holderSection.section.setText(si.getSectionString().toString()); } else { CustomerListViewModel ei = (CustomerListViewModel) objItem; if (convertView == null || !convertView.getTag().equals(holderName)) { convertView = vi.inflate(R.layout.customer_list_item, null); holderName = new ViewHolderName(); convertView.setTag(holderName); } else { holderName = (ViewHolderName) convertView.getTag(); } holderName.name = (TextView) convertView .findViewById(R.id.CustomerName); holderName.email = (TextView) convertView .findViewById(R.id.CustomerEmail); holderName.phone = (TextView) convertView .findViewById(R.id.CustomerPhone); if (holderName.name != null) holderName.name.setText(ei.getCustomerName()); holderName.email.setText(ei.getCustomerEmail()); holderName.phone.setText(ei.getCustomerPhone()); } return convertView; } public static class ViewHolderName { public TextView name; public TextView email; public TextView phone; } public static class ViewHolderSectionName { public TextView section; } [/code] Подробнее здесь: [url]https://stackoverflow.com/questions/26234788/how-to-load-1000s-of-data-in-listview-efficiently[/url]