接触选择器

发布于 2024-12-18 20:48:21 字数 1763 浏览 2 评论 0原文

我已经为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别低头,皇冠会掉 2024-12-25 20:48:21

正如您提到的,您开始了解游标,因此既然您了解游标的基本功能,它用于保存数据库上的查询返回的数据。因为在上面的代码中您正在查询设备的联系人数据库。并且代码返回游标中的数据,因为您没有进一步使用它。您可以使用光标并执行以下操作,

  1. 获取联系人姓名并在屏幕上显示,
  2. 获取联系人姓名和号码并显示。

下面是示例程序的链接,导入它你会得到更好的想法。

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

  1. take contact name and display on the screen
  2. take contact name and number and display.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文