我有一个带有Firebase数据库的RecyclerView当我单击该项目时,应该显示一个底部工作表对话框当底部对话框显示回收商回到位置0时这是适配器的底页调用
holder.comment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CommentBottomSheetDialog dialog=new CommentBottomSheetDialog(context,user,items.get(position));
dialog.show(fragmentManager,dialog.getTag());
}
});
这是底部工作表加载数据代码
private void loadList() {
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChildren()){
list=new ArrayList<>();
for (DataSnapshot d:dataSnapshot.getChildren()) {
Comments comments=d.getValue(Comments.class);
list.add(comments);
}
CommentsAdapter adapter=new CommentsAdapter(context,list);
rec.setAdapter(adapter);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
[注意:底部工作表还从firebase加载数据
recyclerView.layoutManager.scrollToPosition(position)
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(context) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
现在,您设置要滚动到的位置,如果要滚动到顶部,请在此处设置0。
smoothScroller.setTargetPosition(position);
并将新创建的平滑滚动条作为[传递给LayoutManager
layoutManager.startSmoothScroll(smoothScroller);