开发者

binding adapter to list view

if(cur.moveToFirst())
        {
        do{
            int nameidx=cur.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
            int Ididx=cur.getColumnIndexOrThrow(ContactsContract.Contacts.HAS_PHONE_NUMBER);
            String strName=cur.getString(nameidx);
            String strId=cur.getString(Ididx);
            if(strId.equals("0")) continue;
            Toast.makeText(this,"Contact Name: "+strName, Toast.LENGTH_LONG).show();
            names.add(strName);
            //result[cur.getPosition()]=strName+"("+strId+")";
        }while(cur.moveToNext());
        adapter=new ArrayAdapter<String>(this, R.layout.list_view_item, names);
        setListAdapter(adapter);

this my code and i am getting error at setListAdapter(adapter) as setListAdapter is undefined. please开发者_如何学运维 help me in resolving this error.


You need to have an object of listview

ListView lv = (ListView) findViewById(R.id.lv);

then set adapter to this listview object

lv.setAdapter(adapter);

setListAdapter() works when the class extends the listactivity

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜