简体   繁体   English

抓取联系人并将其显示在列表视图中

[英]Grab contacts and display them into a list view

I am trying to store the list of contacts that are already stored in the contacts list into a List View. 我正在尝试将已经存储在联系人列表中的联系人列表存储到列表视图中。 So far when I click the button nothing actually happens. 到目前为止,当我单击按钮时,实际上没有任何反应。 There are no runtime errors; 没有运行时错误; simply nothing happens. 根本没有任何反应。 This is being run on a Google Nexus 7. 该程序正在Google Nexus 7上运行。

Here is the code. 这是代码。

 contactsList = (ListView) findViewById(R.id.contactsList);
        btnContacts = (Button) findViewById((R.id.btnContacts));
        StoreContacts = new ArrayList<String>();

        // toasts the user that their contacts are now being accessed
//        EnableRuntimePermission();

        btnContacts.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                GetContactsIntoArrayList();

                arrayAdapter = new ArrayAdapter<String>(
                        DisplayInformation.this,
                        R.layout.activity_display_information, // possibly change if it doesn't work
                        R.id.contactsList, StoreContacts
                );

                contactsList.setAdapter(arrayAdapter);
                contactsList.setTextFilterEnabled(true);
}

    });


  public void GetContactsIntoArrayList() {

        cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

        while (cursor.moveToNext()) {

            name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        }
    }
public void GetContactsIntoArrayList() {

    cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

    while (cursor.moveToNext()) {

        name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
StoreConacts.add(name);

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM