[英]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>
尝试使用ArrayAdapter
: http : //developer.android.com/reference/android/widget/ArrayAdapter.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.