【发布时间】:2016-10-05 09:41:01
【问题描述】:
我正在尝试从从 SQLite DB 填充的 RecyclerView 列表中删除项目并收到此错误:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
我正在尝试使用的代码正在处理未从 SQLite 数据库填充的数据,但在这种情况下,它会在长按时崩溃。这是我的代码:
@Override
public void onBindViewHolder(RecHolder holder, final int position) {
final Todo item = listData.get(position);
final int currentPosition = position;
final Todo infoData = listData.get(position);
holder.container.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
removeData(infoData);
return true;
}
});
}
private void removeData(Todo infoData) {
int position = dbTodo.indexOf(infoData);
dbTodo.remove(position);
notifyItemRemoved(position);
}
谁能帮我解决这个问题?
解决方案
我在removeData() 中弄乱了这个db.Todo,它应该是listData,就像在初始化中一样。
【问题讨论】:
标签: java android sqlite android-recyclerview