所以长时间点击我试图在RecyclerView中删除一行。这在ListView中比较容易,但不知怎的,我发现它更难。
这是我的代码:
@Override
public void onBindViewHolder(RecHolder holder, final int position) {
final Todo item = listData.get(position);
holder.container.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
removeData(item);
return true;
}
});
}
private void removeData(Todo infoData) {
int currentPosition = dbTodo.indexOf(infoData);
dbTodo.remove(currentPosition);
notifyItemRemoved(currentPosition);
}
我做错了什么?