【发布时间】:2022-07-07 00:51:13
【问题描述】:
我在 onBindViewHolder 方法中有这个数组。
checklistHelper = dbHelper.getChecklists(id);
String status = checklistHelper.getStatus();
String[] statusSplit = status.split("\n");
ArrayList<String> newStatusList = new ArrayList<>(Arrays.asList(statusSplit));
newStatusList.remove(position);
notifyItemRemoved(position);
int size = newStatusList.size();
我想将大小传递给下面的方法
@Override
public int getItemCount() {
return size;
这样做 getItemCount 不会得到任何值,这意味着我看不到任何项目。如果我想将该代码放入 Adapter 构造函数中,则会显示项目,但在删除一行后,该行将再次重新创建。因为我放不下
newStatusList.remove(position);
notifyItemRemoved(position);
在适配器构造函数内,因为我无法访问适配器构造函数内的 ViewHolder 位置。
感谢任何帮助。
【问题讨论】:
-
你知道
getItemCount()是用来支持适配器的数据计数的吧?该数组是否为您的适配器提供数据?如果是这样,为什么不在适配器中将其声明为全局字段? -
@Kozmotronik 我做到了,谢谢。