android 联系人查询以数字形式返回联系人姓名
我正在尝试查询数据库并显示联系人及其所有电话号码,每个电话号码一行:
活动文件:
private Cursor getContacts() {
Uri uri = Data.CONTENT_URI;
String[] fields = new String[] {
Data._ID,
Phone.NUMBER,
Data.DISPLAY_NAME,
Phone.LABEL,
Phone.TYPE,
};
String sortOrder = Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(uri, fields, null, null, sortOrder);
}
private void populateContactList() {
Cursor cursor = getContacts();
String[] fields = new String[] {
Data.DISPLAY_NAME,
Phone.NUMBER,
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_details, cursor,
fields, new int[] {R.id.contactNameText, R.id.contactNumberText });
mContactList.setAdapter(adapter);
}
我获得了所需的所有信息,但它还显示每个联系人姓名两次(就好像它是电话号码一样)在其中一行中:
有谁知道做错了什么?任何帮助将不胜感激!
[这里是 XML 文件(尽管不认为它们是问题的根源)]:
//contact_list.xml <ListView android:layout_width="fill_parent"
android:id="@+id/contactList"
android:layout_height="wrap_content"
android:layout_weight="1"/>
//contact_details.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="@+id/contactNumber"
android:id="@+id/contactNumberText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dip"
/>
<TextView android:text="@+id/contactName"
android:id="@+id/contactNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/contactNumberText"
/>
Am trying to query the database and display contacts and all their phone numbers, a row for each phone number:
Activity file:
private Cursor getContacts() {
Uri uri = Data.CONTENT_URI;
String[] fields = new String[] {
Data._ID,
Phone.NUMBER,
Data.DISPLAY_NAME,
Phone.LABEL,
Phone.TYPE,
};
String sortOrder = Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(uri, fields, null, null, sortOrder);
}
private void populateContactList() {
Cursor cursor = getContacts();
String[] fields = new String[] {
Data.DISPLAY_NAME,
Phone.NUMBER,
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_details, cursor,
fields, new int[] {R.id.contactNameText, R.id.contactNumberText });
mContactList.setAdapter(adapter);
}
I get all the info I need, but it also shows every contacts name twice (as if it were the phone number) in one of the rows:
Does anyone know what am doing wrong? any help will be appreciated!
[Here are the XML files (although don't think they are the source of the problem)]:
//contact_list.xml <ListView android:layout_width="fill_parent"
android:id="@+id/contactList"
android:layout_height="wrap_content"
android:layout_weight="1"/>
//contact_details.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="@+id/contactNumber"
android:id="@+id/contactNumberText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dip"
/>
<TextView android:text="@+id/contactName"
android:id="@+id/contactNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/contactNumberText"
/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用此代码代替您的方法
}
Try this code instead your method
}