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

时间:2017-04-05 00:24:30

标签: java android listview

我正在尝试将已存储在联系人列表中的联系人列表存储到列表视图中。到目前为止,当我点击按钮时,实际上没有发生任没有运行时错误;根本没有任何反应这是在Google Nexus 7上运行。

这是代码。

 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));
        }
    }

1 个答案:

答案 0 :(得分:0)

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);

    }
}
相关问题