如何在listview中高效加载1000条数据

问题描述 投票:0回答:2

我有 1000 个客户需要从服务器加载到自定义列表视图中。但我需要更多时间来填充列表视图。我正在使用搜索选项来搜索客户,因此我需要一次性加载并显示所有客户。我无法从本地数据库显示它,因为我可能会在列表视图中编辑项目单击的详细信息并将其存储在服务器中。任何人都可以帮助我以有效的方式加载自定义列表视图吗?

  public class CustomersAdapter extends ArrayAdapter<Item> {

private ArrayList<Item> items;
private LayoutInflater vi;
private Item objItem;

ViewHolderSectionName holderSection;
ViewHolderName holderName;

public CustomersAdapter(Context context, ArrayList<Item> 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;
}

}

android listview android-listview
2个回答
0
投票

尝试在列表视图中使用viewHolder,它将每个组件视图存储在布局的标签字段内,因此您可以立即访问它们,而无需重复查找它们。这个LINK可能对您有帮助。


0
投票

您可以使用

BaseAdapter
。请参阅此链接链接

© www.soinside.com 2019 - 2024. All rights reserved.