接触选择器
我已经为 Comp Eng 移动应用程序类的介绍而研究这个单一函数大约一周了,开始了解游标、内容解析器和适配器。但是代码认识到我从不使用光标,但我不知道如何将光标合并到这个程序中。
public class HelloAutoCompleteActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContentResolver content = getContentResolver();
Cursor cursor = content.query(Contacts.CONTENT_URI, PEOPLE_PROJECTION, null, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC");
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, PEOPLE_PROJECTION);
// textView.ContactListAdapter adapter = new textView.ContactListAdapter(this, cursor);
textView.setAdapter(adapter);
}
private static final String[] PEOPLE_PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.LABEL,
ContactsContract.Contacts.DISPLAY_NAME
};
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts._COUNT,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
//Get the base URI for the People table in the Contacts content provider.
Uri contacts = ContactsContract.AUTHORITY_URI;
////Make the query.
Cursor cursor;
}
I've been working on this single function for my intro to Comp Eng Mobile App Class, for about a week, starting to understand Cursors, contentresolvers, and adapters. But the code, recognizes I never use a cursor, but I don't know how to incorporate cursor into this program.
public class HelloAutoCompleteActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContentResolver content = getContentResolver();
Cursor cursor = content.query(Contacts.CONTENT_URI, PEOPLE_PROJECTION, null, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC");
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, PEOPLE_PROJECTION);
// textView.ContactListAdapter adapter = new textView.ContactListAdapter(this, cursor);
textView.setAdapter(adapter);
}
private static final String[] PEOPLE_PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.LABEL,
ContactsContract.Contacts.DISPLAY_NAME
};
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts._COUNT,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
//Get the base URI for the People table in the Contacts content provider.
Uri contacts = ContactsContract.AUTHORITY_URI;
////Make the query.
Cursor cursor;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您提到的,您开始了解游标,因此既然您了解游标的基本功能,它用于保存数据库上的查询返回的数据。因为在上面的代码中您正在查询设备的联系人数据库。并且代码返回游标中的数据,因为您没有进一步使用它。您可以使用光标并执行以下操作,
下面是示例程序的链接,导入它你会得到更好的想法。
http://l8rs.blogspot.com/2009 /03/android-sample-list-contact-book-and.html
As you mentioned you started understanding the Cursor, so since you are aware of basic function of the cursor, it used to hold the data returned by the Query on the database. since in the above code you are querying the Contact database of the device. and the code returns data in the cursor, since you are not using that further. you can use cursor and do below
Below is the link for the sample program, import it you will get better idea.
http://l8rs.blogspot.com/2009/03/android-sample-list-contact-book-and.html