如何显示在ListView手机通讯录通讯录、手机、ListView

2023-09-06 22:14:54 作者:醉生梦死﹌

以下是我的code,其实在屏幕上它没有显示我的任何接触。在模拟器我有5个联系人补充道。请告诉我该怎么做。

  {
    //一些code
    光标CUR = getContacts();
    的String []字段=新的String [] {ContactsContract.Data.DISPLAY_NAME};
    SimpleCursorAdapter适配器=
        新SimpleCursorAdapter(这一点,
                                R.layout.list_view_item_new,
                                CUR,
                                场,
                                新的INT [] {R.id.contactEntryText});
    lv.setAdapter(适配器);
}

私人光标getContacts(){
    //运行查询
    开放的我们的uri = ContactsContract.Contacts.CONTENT_URI;
    的String []投影=
        新的String [] {ContactsContract.Contacts._ID,
                      ContactsContract.Contacts.DISPLAY_NAME};
    串选择= NULL;
    的String [] selectionArgs两个= NULL;
    字符串排序顺序= ContactsContract.Contacts.DISPLAY_NAME +
        分页中局部ASC;
    返回managedQuery(URI,投影,选择,selectionArgs两个,排序顺序);
}
 

解决方案

我已经复制并执行几乎同样的code和它的作品:

 公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        光标CUR = getContacts();

        ListView的LV = getListView();

       的String []字段=新的String [] {ContactsContract.Data.DISPLAY_NAME};

       SimpleCursorAdapter适配器=
                新SimpleCursorAdapter(这一点,
                                        R.layout.main,
                                        CUR,
                                        场,
                                        新的INT [] {R.id.txtbox});
          lv.setAdapter(适配器);
    }

    私人光标getContacts(){
        //运行查询
        开放的我们的uri = ContactsContract.Contacts.CONTENT_URI;

        的String []投影=
                新的String [] {ContactsContract.Contacts._ID,
                              ContactsContract.Contacts.DISPLAY_NAME};
            串选择= NULL;
            的String [] selectionArgs两个= NULL;
            字符串排序顺序= ContactsContract.Contacts.DISPLAY_NAME +
                分页中局部ASC;
            返回managedQuery(URI,投影,选择,selectionArgs两个,排序顺序);
    }
 

请检查您是否在TextView中实施做错了什么?

华为手机通讯录里联系人如何显示在微信

Following is my code, actually on screen it's not showing me any contact. In emulator I have 5 contacts added. Please tell me what to do.

{
    //some code
    Cursor cur = getContacts();
    String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME};
    SimpleCursorAdapter adapter = 
        new SimpleCursorAdapter(this, 
                                R.layout.list_view_item_new,
                                cur,
                                fields,
                                new int[] {R.id.contactEntryText});
    lv.setAdapter(adapter);
}

private Cursor getContacts() {  
    // Run query     
    Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String[] projection = 
        new String[]{ ContactsContract.Contacts._ID,
                      ContactsContract.Contacts.DISPLAY_NAME }; 
    String selection = null;
    String[] selectionArgs = null;  
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + 
        " COLLATE LOCALIZED ASC";  
    return managedQuery(uri, projection, selection, selectionArgs, sortOrder);  
}

解决方案

I have copied and executed almost the same code and it works:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Cursor cur = getContacts();

        ListView lv = getListView();

       String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME};

       SimpleCursorAdapter adapter = 
                new SimpleCursorAdapter(this, 
                                        R.layout.main,
                                        cur,
                                        fields,
                                        new int[] {R.id.txtbox});
          lv.setAdapter(adapter);         
    }    

    private Cursor getContacts() {  
        // Run query     
        Uri uri = ContactsContract.Contacts.CONTENT_URI;

        String[] projection = 
                new String[]{ ContactsContract.Contacts._ID,
                              ContactsContract.Contacts.DISPLAY_NAME }; 
            String selection = null;
            String[] selectionArgs = null;  
            String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + 
                " COLLATE LOCALIZED ASC";  
            return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
    }

Please check if you have done anything wrong in the textview implementation?