2010-11-01 79 views
0

中显示联系人的名字,我想只要从设备电话簿中的联系人,并在旋转器上,代码显示出来:安卓:在微调

// 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是空的......任何人都可以告诉我我做错了吗?

回答

0

原来,sdk不支持> 2.0