如何快速联系人装载在Android的ListView [英] How to fast the contacts loading in listview on android

查看:93
本文介绍了如何快速联系人装载在Android的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我列出一个列表视图联系人。无接触的是1000+。我得到的接触

使用的 ContentResolver的查询这是cr.query(...),该值存储在一个ArrayList

和该负荷后在setListAdapter数组列表(...)。显示所有联系人我的

应用程序需要近1分钟,从而我使用异步任务异步使用的任务,但是没有大的差异。

我需要2到4秒内显示所有联系人。我检查在默认通讯录
在Android模拟器应用程序,它是在2到4秒内的负载。
我有支出

很长一段时间在谷歌。但我无法得到任何有用的解决方案。请帮助我如何快速列表视图上装载的接触。请帮帮我。

我的编码样本:

 私人的ArrayList< ContactListEntry> loadContactListInternal(字符串搜索字符串){
        ArrayList的< ContactListEntry> contactList =新的ArrayList< ContactListEntry>();
    ContentResolver的CR = getContentResolver();
    光标CUR = NULL;
    的String [] =投影新的String [] {BaseColumns._ID,ContactsContract.Contacts.DISPLAY_NAME,ContactsContract.Contacts.PHOTO_ID};
    ....
        CUR = cr.query(ContactsContract.Contacts.CONTENT_URI,投影,选择,空,ContactsContract.Contacts.DISPLAY_NAME +ASC);    而(cur.moveToNext()){
         INT ID =的Integer.parseInt(cur.getString(0));
             ....
        如果(输入!= NULL)
            照片= BitmapFactory.de codeStream(输入);
         ....
        ArrayList的< ContactListEntry.PhoneEntry> phoneEntries =新的ArrayList< ContactListEntry.PhoneEntry>();            的String [] = projection1新的String [] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.TYPE};
            光标pcur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,projection1,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +=?,新的String [] {将String.valueOf(ID)},NULL);
            而(pcur.moveToNext()){
                ...
            }
            pcur.close();            ContactListEntry进入=新ContactListEntry(ID,姓名,照片,phoneEntries);
            contactList.add(输入);
    }
    cur.close();    返回contactList;
}
    .....
    另一类
        私人无效selectionUpdated(){
                ....
         setListAdapter(新SelectedArrayAdapter(这一点,app.selectedContacts));
            ...
       }


解决方案

我使用光标适配器和我切DATABSE,arrayadapter和优化code。

in my app i am listing contacts in a listview. no of contacts is 1000+. i get the contacts

by using ContentResolver query that is cr.query(...),store the values in an arraylist

and after that load the array list in setListAdapter(...). to display the all contacts my

apps takes nearly 1 minute so that i use Async task but there is no big differences by using the async task.

i need to display all contacts within 2 to 4 seconds. i check in the default contacts application on android simulator which is load within in 2 to 4 seconds. i have spend

long time in google. but i could not get any helpful solution. please help me how to fast the loading contacts on listview. please help me.

my coding sample:

    private ArrayList<ContactListEntry> loadContactListInternal(String searchString) {
        ArrayList<ContactListEntry> contactList = new ArrayList<ContactListEntry>();
    ContentResolver cr = getContentResolver();
    Cursor cur = null;
    String[] projection = new String[] {BaseColumns._ID,ContactsContract.Contacts.DISPLAY_NAME,ContactsContract.Contacts.PHOTO_ID};
    ....
        cur=cr.query(ContactsContract.Contacts.CONTENT_URI, projection, selection, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC");

    while (cur.moveToNext()) {
         int id = Integer.parseInt(cur.getString(0));
             ....   
        if (input !=null)
            photo = BitmapFactory.decodeStream(input);
         ....
        ArrayList<ContactListEntry.PhoneEntry> phoneEntries = new ArrayList<ContactListEntry.PhoneEntry>();

            String[] projection1 = new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.TYPE};    
            Cursor pcur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,projection1, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { String.valueOf(id) }, null);
            while (pcur.moveToNext()) {
                ...
            }
            pcur.close();

            ContactListEntry entry = new ContactListEntry(id, name, photo, phoneEntries);
            contactList.add(entry);
    }
    cur.close();

    return contactList;
}
    .....
    in another class
        private void selectionUpdated() {
                ....
         setListAdapter(new SelectedArrayAdapter(this, app.selectedContacts));
            ... 
       }

解决方案

i use cursor adapter and i cut the databse,arrayadapter and optimize the code.

这篇关于如何快速联系人装载在Android的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆