android - 更新 ListView,即使其适配器为 null

标签 android listview adapter

即使适配器为 null,我也想更新我的列表,但我不知道该怎么做。

当我执行以下代码时,我的应用程序崩溃了:

ProductAdapter adapter = new ProductAdapter(context, R.layout.listrow, yal);
if(adapter.getCount()>0){
   lv.setAdapter(adapter);
}else{
   lv.setAdapter(null);
}
adapter.notifyDataSetChanged();
lv.invalidateViews();

最佳答案

适配器是列表的数据源。它提供了单独的列表项。没有适配器就没有列表,因为那样列表中就没有行。

查看 ListView documentation获取更多信息。

关于android - 更新 ListView,即使其适配器为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15385646/

相关文章:

安卓蓝牙 : Unable to connect to listening socket after generating a random UUID

android - 如何使用带有 ListView 而不是 Recycler View 的折叠工具栏

listview - 在JavaFX中更新ListView时出现IndexOutOfBoundsException

java - Java 中的 mousePressed() 方法似乎不起作用

design-patterns - 对象适配器模式和类适配器模式的区别

android - 如何防止通知栏在新通知上滚动动画

Java mac sha256 哈希与使用 pack 的 php hmac sha256 不匹配?

Android 异常 getCause - getMessage

android - 如何缓存android ListView 的图像

android - ListView 中的动画列表项