Я получил подробную информацию о книгах из пожарной базы и добавил в список «BookList».Книги добавляются, и я устанавливаю представление и адаптер утилиты, но когда я запускаю приложение, оно ничего не показывает.Я не знаю, что не так с моим кодом
Любая помощь будет высоко оценена, спасибо.
1) WishListActivity
public class WishListActivity extends AppCompatActivity {
RecyclerView recyclerView;
FirebaseUser CurrentUser;
String CurrentUserEmail;
WishListAdapter wishListAdapter;
List<BooksModel> BookList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wish_list);
CurrentUser = FirebaseAuth.getInstance().getCurrentUser();
CurrentUserEmail = CurrentUser.getEmail();
recyclerView = findViewById(R.id.recyclerView_WishList);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
BookList = new ArrayList<>();
DatabaseReference WishListRef =
FirebaseDatabase.getInstance().getReference("wishlist");
WishListRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
for(DataSnapshot
WishListSnapshot:dataSnapshot.getChildren()){
WishListModel Model =
WishListSnapshot.getValue(WishListModel.class);
if(Model.getEmail().equals(CurrentUserEmail)){
DatabaseReference BookReference =
FirebaseDatabase.getInstance().getReference("Books").child(Model.getKey());
BookReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
BooksModel Book = dataSnapshot.getValue(BooksModel.class);
BookList.add(Book);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
else{
Toast.makeText(WishListActivity.this, "Email Not Matched! ", Toast.LENGTH_SHORT).show();
}
}
wishListAdapter = new WishListAdapter(WishListActivity.this,BookList);
recyclerView.setAdapter(wishListAdapter);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
WishListAdapter
public class WishListAdapter extends RecyclerView.Adapter<WishListAdapter.WishListViewHolder>{
private Context context;
private List<BooksModel> mDatalist;
public WishListAdapter(Context context, List<BooksModel> mDatalist) {
this.context = context;
this.mDatalist = mDatalist;
}
@NonNull
@Override
public WishListViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View rootView = LayoutInflater.from(context).inflate(R.layout.wish_list,viewGroup
,false);
WishListViewHolder wishListViewHolder = new WishListViewHolder(rootView);
return wishListViewHolder;
}
@Override
public void onBindViewHolder(@NonNull WishListViewHolder wishListViewHolder, int i) {
final BooksModel Book = mDatalist.get(i);
wishListViewHolder.BookName.setText(Book.getName());
wishListViewHolder.BookPrice.setText(Book.getPrice());
wishListViewHolder.AuthorName.setText(Book.getAuthor());
wishListViewHolder.RemoveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "Remove Button Clicked! ", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount() {
return mDatalist.size();
}
public class WishListViewHolder extends RecyclerView.ViewHolder{
TextView BookName,BookPrice,AuthorName;
Button RemoveButton;
public WishListViewHolder(@NonNull View itemView) {
super(itemView);
BookName = itemView.findViewById(R.id.book_price_wish_list);
BookPrice = itemView.findViewById(R.id.book_price_wish_list);
RemoveButton = itemView.findViewById(R.id.remove_book_wish_list);
}
}
}
код активности списка желаний