Java 活动中未显示联系人
我试图在活动中显示联系人,但它不起作用。 我检查了代码,但无法理解问题所在。 这是我的密码:- /删除/ showfriendlist.xmlJava 活动中未显示联系人,java,android,listview,Java,Android,Listview,我试图在活动中显示联系人,但它不起作用。 我检查了代码,但无法理解问题所在。 这是我的密码:- /删除/ showfriendlist.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_paren
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/lst_contacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
将代码更改为:
// The contacts from the contacts content provider is stored in this cursor
mMatrixCursor = new MatrixCursor(new String[]{"_id", "name", "photo", "details"});
// Adapter to set data in the listview
mAdapter = new SimpleCursorAdapter(getBaseContext(),
R.layout.lv_layout,
mMatrixCursor,
new String[]{"name", "photo", "details"},
new int[]{R.id.tv_name, R.id.iv_photo, R.id.tv_details}, 0);
您没有将光标传递给
SimpleCorsOrAdapter
使用光标获取移动联系人
Cursor c = getContentResolver().query(Phone.CONTENT_URI, null,
null, null, Phone.DISPLAY_NAME + " ASC");
while (c.moveToNext()) {
contactName = c
.getString(c
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
phNumber = c
.getString(c
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}