gpt4 book ai didi

android - ListView 不显示适配器

转载 作者:行者123 更新时间:2023-11-30 04:35:09 24 4
gpt4 key购买 nike

有了这段代码

            final ListView lw   =   (ListView) findViewById( R.id.book_list );
lw.setVisibility(View.VISIBLE);

ListView listBookView = (ListView) findViewById( R.id.book_list );
ArrayList<HashMap<String, Object>> my_list = new ArrayList<HashMap<String, Object>>();

for ( int x=0; x< book_list.size(); x++)
{
String[] valori_book = book_list.get( x ).getObjVars();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("book", valori_book[ 0 ]);
map.put("descr", valori_book[ 1 ] );

my_list.add(map);
}
// ...
SimpleAdapter showMenu = new SimpleAdapter(this, my_list, R.layout.activity_book_booklistmask,
new String[] { "book" , "descr" }, new int[] {R.id.nome_quaderno, R.id.descrizione_quaderno});
listBookView.setAdapter(showMenu);

java.lang.IllegalStateException: android.widget.ListView 不是一个可以被这个 SimpleAdapter 限制的 View

logcat 没有写我项目的错误行,所以我不知道在哪里检查:/

E/AndroidRuntime(  904): java.lang.IllegalStateException: android.widget.ListView is not a  view that can be bounds by this SimpleAdapter
E/AndroidRuntime( 904): at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:195)
E/AndroidRuntime( 904): at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
E/AndroidRuntime( 904): at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
E/AndroidRuntime( 904): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
E/AndroidRuntime( 904): at android.widget.ListView.makeAndAddView(ListView.java:1727)
E/AndroidRuntime( 904): at android.widget.ListView.fillDown(ListView.java:652)
E/AndroidRuntime( 904): at android.widget.ListView.fillFromTop(ListView.java:709)
E/AndroidRuntime( 904): at android.widget.ListView.layoutChildren(ListView.java:1580)
E/AndroidRuntime( 904): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
E/AndroidRuntime( 904): at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 904): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
E/AndroidRuntime( 904): at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 904): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
E/AndroidRuntime( 904): at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 904): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
E/AndroidRuntime( 904): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
E/AndroidRuntime( 904): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
E/AndroidRuntime( 904): at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 904): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
E/AndroidRuntime( 904): at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 904): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
E/AndroidRuntime( 904): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
E/AndroidRuntime( 904): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 904): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 904): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 904): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 904): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 904): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 904): at dalvik.system.NativeStart.main(Native Method)

最佳答案

来自 SimpleAdapter 文档

实现 Checkable 的 View (例如 CheckBox)。预期的绑定(bind)值是一个 bool 值。

TextView 。预期的绑定(bind)值是一个字符串,并且调用了 setViewText(TextView, String)。

ImageView 。预期的绑定(bind)值是资源 ID 或字符串,并调用 setViewImage(ImageView, int) 或 setViewImage(ImageView, String)。

似乎将对象作为映射对象传递与 SimpleAdapter 不兼容。更改对象类型,或创建自定义适配器(我推荐后者)

关于android - ListView 不显示适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6958696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com