kAnNaN
kAnNaN

Reputation: 3679

SimpleCursorAdapter for ListView?

in my app i need to use the SimpleCursorAdapter for my listview which is being populated by an string[] or ArrayList[]...

i tried the following code:

ArrayList<String> mDisplay = new ArrayList<String>();
Cursor c = (Cursor) mDisplay.iterator();
    lv_contactlist.setAdapter(new SimpleCursorAdapter(this, android.R.layout.simple_list_item_checked, c ,new String[]{mDisplay.toString()}, new int[]{android.R.id.text1}));

but show me error as follows:

Caused by: java.lang.ClassCastException: java.util.ArrayList$ArrayListIterator at com.kpj4s.way2sms.ContactsList.onCreate(ContactsList.java:62) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)

i think that the Cursor object "c" is not properly set

can any one help me with the code or show me the alternative (note: i need to use only SimpleCursorAdapter)

thanks :)

Upvotes: 0

Views: 1739

Answers (1)

djg
djg

Reputation: 1283

A Cursor is usually the result of a database query. You are not querying a database and an Iterator is not a Cursor, hence the ClassCastException.

If you are hoping to query a ContentProvider to collect the Contact information see the section "Querying a Content Provider" at http://developer.android.com/guide/topics/providers/content-providers.html

If you really only want to display your ArrayList<String> try ArrayAdapter: http://developer.android.com/reference/android/widget/ArrayAdapter.html

Upvotes: 2

Related Questions