简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM