firebaseRecyCleadapter以正确的方式添加了清洁式



我有一个FirebaseRecyclerAdapter,我尝试添加我使用ItemTouchHelper.SimpleCallback创建的开关方法。下面是我的代码,在刷卡时尝试删除火箱条目。下面的代码确实确实删除了firebase条目,只是它始终删除列表中的最后一个条目。我希望这与以错误的方式解析list_id有关。也许可以在PopulateViewHolder内部调用onswipe?

private String other_id;

protected void onStart() {
    super.onStart();
final FirebaseRecyclerAdapter<Lists, ListAdapter.ListsViewHolder> listsRecycleViewAdapter = new FirebaseRecyclerAdapter<Lists, ListAdapter.ListsViewHolder>(
            Lists.class,
            R.layout.list_single_layout,
            ListAdapter.ListsViewHolder.class,
            mDoneListRef

    ) {
        @Override
        protected void populateViewHolder(final ListAdapter.ListsViewHolder viewHolder, Lists model, final int position) {
            final String list_id = getRef(viewHolder.getAdapterPosition()).getKey();
            other_id = list_id;
            mDoneListRef.child(list_id).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (dataSnapshot.exists()) {
                    //do stuff
                    }
                }
                @Override
                public void onCancelled(DatabaseError databaseError) {
                }
            });
        }
    };
    mListView.setAdapter(listsRecycleViewAdapter);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction, int position) {

    mDoneListRef.child(other_id).removeValue();
}

您需要查找被传递到onSwipedposition参数刷的项目。这些行:

public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction, int position) {
    listsRecycleViewAdapter.getRef(position).removeValue();
}

相关内容

  • 没有找到相关文章

最新更新