Android RecycleView不显示列表中的数据 [英] Android RecycleView does not show data in list

查看:584
本文介绍了Android RecycleView不显示列表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 this.books = new ArrayList<>();
            mFirebaseDatabaseReference.child(SellBooksPost).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange( DataSnapshot AdataSnapshot) {

                    for (final DataSnapshot AmessageSnapshot : AdataSnapshot.getChildren()) {

                        bFirebaseDatabaseReference.child(mUserId).addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot BdataSnapshot) {

                            for (DataSnapshot BmessageSnapshot : BdataSnapshot.getChildren()) {
                                if (BmessageSnapshot.child("book").getValue().toString().equals(AmessageSnapshot.child("SellBooksPostId").getValue().toString())){
                                    Log.d("INFO", "SELL BOOK book " + BmessageSnapshot.child("book").getValue());
                                    Log.d("INFO", "SELL BOOK DETAIL " + AmessageSnapshot.child("SellBooksPostId").getValue());

                                    books.add(new Book(

                                            AmessageSnapshot.child("SellBooksPostId").getValue().toString(),
                                            AmessageSnapshot.child("bookTitle").getValue().toString()
                                    ));

                                }
                            }
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                        }
                    });

                }

                saleBookPostAdapter = new SaleBookPostAdapter(getApplicationContext(), books);
                mRoomRecyclerView.setHasFixedSize(true);
                mRoomRecyclerView.setAdapter(saleBookPostAdapter);

推荐答案

很难说这是否是一个问题,但是我看不到对

It's hard to say if this is a problem, but I do not see a call to RecyclerView.Adapter#notifyDataSetChanged() method after updating the data. So try call

salesBookAdapter.notifyDataSetChanged()

之后

books.add(new Book(
     AmessageSnapshot.child("SellBooksPostId").getValue().toString(),
     AmessageSnapshot.child("bookTitle").getValue().toString()
));

这篇关于Android RecycleView不显示列表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆