简体   繁体   English

ListView的SimpleCursorAdapter?

[英]SimpleCursorAdapter for ListView?

in my app i need to use the SimpleCursorAdapter for my listview which is being populated by an string[] or ArrayList[]... 在我的应用程序中,我需要使用SimpleCursorAdapter作为我的listview,它由字符串[]或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) 引起: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 我认为Cursor对象“c”没有正确设置

can any one help me with the code or show me the alternative (note: i need to use only SimpleCursorAdapter) 可以任何人帮我代码或给我看替代(注意:我只需要使用SimpleCursorAdapter)

thanks :) 谢谢 :)

A Cursor is usually the result of a database query. Cursor通常是数据库查询的结果。 You are not querying a database and an Iterator is not a Cursor , hence the ClassCastException . 您没有查询数据库,并且Iterator不是Cursor ,因此是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 如果您希望查询ContentProvider以收集联系信息,请参阅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 如果你真的只想显示你的ArrayList<String>尝试使用ArrayAdapterhttp//developer.android.com/reference/android/widget/ArrayAdapter.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有ContentProvider的SimpleCursorAdapter; ListView为空 - SimpleCursorAdapter with ContentProvider; ListView empty Android-使用SimpleCursorAdapter动态ListView - Android - Dynamically ListView using SimpleCursorAdapter 具有SimpleCursorAdapter的Android ListView-CursorIndexOutOfBoundsException错误 - Android ListView with SimpleCursorAdapter - CursorIndexOutOfBoundsException error 在 Android 中使用 SimpleCursorAdapter 填充列表视图 - Populate listview using SimpleCursorAdapter in Android 如何使用 SimpleCursorAdapter 和 ListView 过滤联系人 - How to Filter Contacts using SimpleCursorAdapter and ListView 在ListView中使用带有文本和图像的MatrixCursor和SimpleCursorAdapter - Using MatrixCursor and SimpleCursorAdapter in a ListView with text and images 我可以在SimpleCursorAdapter listView中放置按钮吗? - Can I put buttons in SimpleCursorAdapter listView? 通过SimpleCursorAdapter在自定义ListView中从SQL显示数据 - Display Data from SQL in custom ListView via SimpleCursorAdapter 我们如何使用SimpleCursorAdapter将数据库中的ID用作Listview ID? - How can we use an ID from database as Listview ID using SimpleCursorAdapter? ListView 没有向我显示一个包含数据库名称的列表。 我使用 SimpleCursorAdapter - The ListView doesn't show me a list with names from database. I use SimpleCursorAdapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM