开发者

binding adapter to list view

开发者 https://www.devze.com 2023-02-13 07:34 出处:网络
if(cur.moveToFirst()) { do{ int nameidx=cur.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
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

精彩评论

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