以下是我的数据库结构
我在活动中创建了一个recyclerView,以显示用户所做的所有预订。 Recycler View工作正常,但问题是它显示了每个用户所做的预订的所有细节。我想只显示当前登录用户所做的预订。下面是主要活动
public class ViewBooking extends Fragment {
FirebaseDatabase mdatabase;
DatabaseReference refbooking;
RecyclerView recycler_booking;
RecyclerView.LayoutManager layoutManager;
FirebaseRecyclerAdapter<Booking, BookingViewHolder> madpter;
String userEmail;
FirebaseUser user;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v= inflater.inflate(R.layout.view_booking, null);
mdatabase=FirebaseDatabase.getInstance();
user= FirebaseAuth.getInstance().getCurrentUser();
userEmail = user.getEmail();
recycler_booking=(RecyclerView)v.findViewById(R.id.BookingRecyclerView);
recycler_booking.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity());
recycler_booking.setLayoutManager(layoutManager);
onStart();
return v;
}
@Override
public void onStart() {
super.onStart();
Query query = mdatabase.getReference("Bookings").orderByChild("userEmail").equalTo(userEmail);
madpter = new FirebaseRecyclerAdapter<Booking, BookingViewHolder>(Booking.class, R.layout.viewbooking_layout, BookingViewHolder.class, query) {
@Override
protected void populateViewHolder(BookingViewHolder viewHolder, Booking model, int position) {
viewHolder.bookedplace.setText(model.getNameOfPlace());
viewHolder.bookedplace.setText(model.getNameOfPlace());
viewHolder.bookedslot.setText(model.getSlotnumber());
viewHolder.bookeddate.setText(model.getCurrentDate());
viewHolder.bookedduration.setText(model.getDuration());
viewHolder.bookedstarttime.setText(model.getStartTime());
}
};
recycler_booking.setAdapter(madpter);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("View Booking");
}
}
我创建了一个String userEmail,通过Auth
获取当前用户的电子邮件ID代码在没有查询的情况下工作正常,并显示所有预订。但添加查询后,回收站视图上没有显示任何内容
答案 0 :(得分:0)
你缺少听众:
@Override
public void onStart() {
super.onStart();
madpter.startListening();
}
@Override
public void onStop() {
super.onStop();
madpter.stopListening();
}