Neha
Neha

Reputation: 187

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.

Upvotes: 1

Views: 2716

Answers (1)

ingsaurabh
ingsaurabh

Reputation: 15269

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

Upvotes: 3

Related Questions