ContactsContract.Contacts 默认为空吗?
ContactsContract.Contacts 默认为空吗?如果是这样,我如何向其中添加一些测试数据?
否则,我一定做错了什么/遗漏了一些东西,因为此活动显示完全为空。
public class Authorize_Activity extends ListActivity {
Cursor mContacts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Return all contacts, ordered by name
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME }; // Would like the phone num, too
mContacts = managedQuery(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, ContactsContract.Contacts.DISPLAY_NAME);
// Display all contacts in a ListView
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, mContacts,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { android.R.id.text1 });
setListAdapter(mAdapter);
}
我的理解是android的simple_list_item_1应该提供“View”,这样我就不需要调用SetContentView()。
但是,尽管我的活动正在显示,但其中没有显示任何数据。那么……我只是缺少联系人数据,还是有更邪恶的事情正在发生?
Is ContactsContract.Contacts by default empty? If so, how do I add some test data to it?
Otherwise, I must be doing something wrong/omitting something, as this Activity displays completely empty.
public class Authorize_Activity extends ListActivity {
Cursor mContacts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Return all contacts, ordered by name
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME }; // Would like the phone num, too
mContacts = managedQuery(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, ContactsContract.Contacts.DISPLAY_NAME);
// Display all contacts in a ListView
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, mContacts,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { android.R.id.text1 });
setListAdapter(mAdapter);
}
My understanding is that android's simple_list_item_1 should provide the "View" so that I don't need to call SetContentView().
But although my Activity is displaying, no data appears in it. So...am I just missing Contacts data, or is something more nefarious afoot?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是模拟器上的吗?
如果是这样,那么默认情况下联系人列表为空我不会感到惊讶。尝试使用模拟器的联系人/人员应用程序添加一些虚假联系人。
Is this on an emulator?
If so then it wouldn't surprise me if the contacts list is empty by default. Try using the emulator's contacts / people app to add some fake contacts.