Android:在Spinner中显示联系人姓名

时间:2010-11-01 15:28:12

标签: android android-emulator

我正在尝试简单地从设备电话簿中获取联系人并将其显示在Spinner上,代码:

    // Form an array specifying which columns to return. 
    String[] PROJECTION = new String[] {
        People._ID, People.NAME
    };

    // Get the base URI for the People table in the Contacts content provider.
    Uri contacts =  People.CONTENT_URI;

    Spinner contactsSpinner = (Spinner) findViewById(R.id.recipient_names);

    // Make the query.
    Cursor contactsCursor = managedQuery(contacts,
                             PROJECTION, // Which columns to return 
                             null,       // Which rows to return (all rows)
                             null,       // Selection arguments (none)
                             // Put the results in ascending order by name
                             People.NAME + " ASC");

    Log.e("EE", String.valueOf(contactsCursor.getCount()));

    SimpleCursorAdapter sca = new SimpleCursorAdapter(
        this, android.R.layout.simple_spinner_item,
        contactsCursor, new String[] {People.NAME}, new int[] {android.R.id.text1}
    );

    Log.e("EE", String.valueOf(sca.getCount()));

    sca.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    contactsSpinner.setAdapter(sca);

编译并运行正常,只是...日志对于两个Log.e()调用都显示为1,我认为暗示联系人实际上已成功检索,但Spinner是空的...有谁能告诉我我做错了?

1 个答案:

答案 0 :(得分:0)

原来在sdk>上不支持它。 2.0