Sylvester Steele wrote:
> activity.setContentView(R.layout.contacts);
> Cursor C =
> activity.getContentResolver().query(People.CONTENT_URI, null, null,
> null, null);
> activity.startManagingCursor(C);
>
> String[] columns = new String[] {People.NAME};
> int[] names = new int[] {R.id.contactsList};
>
> SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(activity,
> R.layout.contacts, C, columns, names);
> ListView contactsList=
> (ListView)activity.findViewById(R.id.contactsList);
> contactsList.setAdapter(mAdapter);
>
> Here is gives me an exception saying: ListView is not a view that can be
> bounds by this simpleCursorAdapter.
Your names parameter seems out of whack. According to the documentation,
names should be:
"The views that should display column in the "from" parameter. These
should all be TextViews. The first N views in this list are given the
values of the first N columns in the from parameter. "
You appear to be passing it an ID of the ListView itself
(R.id.contactsList). You need to be passing in the ID of some view which
is a child of the view specified in the second parameter to the
SimpleCursorAdapter constructor. The second parameter indicates the view
that should be inflated for each row; the array in the fifth parameter
indicate which widgets the columns returned by the cursor get "poured into".
You may want to look at the List2.java sample code from the M5 SDK
ApiDemos area, as it does pretty much what you're aiming to do. In that
example, they use android.R.layout.simple_list_item_1 as the second
parameter and new int[] {android.R.id.text1} as the last parameter to
the SimpleCursorAdapter constructor.
--
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ -- Available Now!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---