开发者

Trouble showing contact names in ListView

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(th开发者_StackOverflowis,id+"--"+name,Toast.LENGTH_LONG).show();
        }
        ArrayAdapter arr = new ArrayAdapter(this, android.R.layout.simple_list_item_1,name);
        lv.setAdapter(arr);
    }
}

I use this logic for displaying contact names in ListView, but it will not show any names; I get an unexpected error. If I use Toast it works perfectly.


android.R.layout.simple_list_item_1 should be a resource for a TextView

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜