2011-07-11 43 views
0
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    lv=(ListView)findViewById(android.R.id.list); 
    ContentResolver cr=getContentResolver(); 
    Cursor cur=cr.query(ContactsContract.Contacts.CONTENT_URI, null,null,null,null); 

    if(cur.getCount()>0) 
    { 
     int x=0; 
     String name[] = null; 
     while (cur.moveToNext()) 
     { 
      String id = cur.getString(
             cur.getColumnIndex(ContactsContract.Contacts._ID)); 
      name[x]= cur.getString(
            cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
      x++; 

      //Toast.makeText(this,id+"--"+name,Toast.LENGTH_LONG).show(); 
     } 
     ArrayAdapter arr = new ArrayAdapter(this, android.R.layout.simple_list_item_1,name); 
     lv.setAdapter(arr); 
    } 
} 

我使用此逻辑显示ListView中的联系人姓名,但它不会显示任何姓名;我收到一个意外的错误。如果我使用Toast它完美的作品。在ListView中显示联系人名称的问题

+0

邮政资源异常的logcat的请 – Egor

回答

0

android.R.layout.simple_list_item_1应该是一个TextView

相关问题