我在我的项目中使用RecyclerView。我想实现滑动功能。我用这个字体
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
Toast.makeText(getActivity(), "" + swipeDir, Toast.LENGTH_LONG).show();
}
};
但是我不明白,如何用这个位置确定列表中的项目位置和对象?
像这样:
viewHolder.getAdapterPosition();
我的代码中要删除的小片段,onSwiped
int fromPos = viewHolder.getAdapterPosition();
studentList.remove(fromPos);
mAdapter.notifyItemRemoved(fromPos);