Firebaseui-android: FirebaseRecyclerAdapter not showing anything for version 3.1.0

Created on 3 Jan 2018  路  5Comments  路  Source: firebase/FirebaseUI-Android

  • Android device: Samsung Galaxy S8
  • Android OS version: 7.0
  • Google Play Services version: 11.8.0
  • Firebase/Play Services SDK version: 11.8.0
  • FirebaseUI version: 3.1.0

I updated FirebaseUI from version 2.4.0 to 3.1.0 and FirebaseRecyclerAdapter is not working anymore. Since the parameter changed, I changed my code as README said, but it is not showing me anything.

Following is what I had for version 2.4.0.
` messageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
linearLayoutManager = new LinearLayoutManager(this);
//linearLayoutManager.setStackFromEnd(true);
messageRecyclerView.setLayoutManager(linearLayoutManager);

        messages_database = database.getReference("messages");
        mFirebaseAdapter = new FirebaseRecyclerAdapter<Message, MessageViewHolder>(
                Message.class,
                R.layout.item_message,
                MessageViewHolder.class,
                messages_database) {
            @Override
            protected void populateViewHolder(MessageViewHolder viewHolder, Message message, int position) {
                viewHolder.messageTextView.setText(message.getText());
                viewHolder.messengerTextView.setText(message.getName());
                viewHolder.timeTextView.setText(message.getTime());
                if (message.getPhotoUrl() == null) {
                    IconicsDrawable iconicsDrawable = new IconicsDrawable(MainActivity.this, Ionicons.Icon.ion_ios_contact_outline).sizeDp(36).color(message.getColor());
                    viewHolder.messengerImageView.setImageDrawable(iconicsDrawable);
                } else {
                    Glide.with(MainActivity.this)
                            .load(message.getPhotoUrl())
                            .into(viewHolder.messengerImageView);
                }
            }
        };

`

And I changed the code above to the one on the bottom for version 3.1.0.
` messageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setStackFromEnd(true);
messageRecyclerView.setLayoutManager(linearLayoutManager);

        messages_database = database.getReference("messages");
        FirebaseRecyclerOptions<Message> options = new FirebaseRecyclerOptions.Builder<Message>().setQuery(messages_database, Message.class).build();

        mFirebaseAdapter = new FirebaseRecyclerAdapter<Message, MessageViewHolder>(options) {
            @Override
            public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.item_message, parent, false);

                return new MessageViewHolder(view);
            }

            @Override
            protected void onBindViewHolder(MessageViewHolder viewHolder, int position, Message message) {
                viewHolder.messageTextView.setText(message.getText());
                viewHolder.messengerTextView.setText(message.getName());
                viewHolder.timeTextView.setText(message.getTime());
                if (message.getPhotoUrl() == null) {
                    IconicsDrawable iconicsDrawable = new IconicsDrawable(ChatActivity.this, Ionicons.Icon.ion_ios_contact_outline).sizeDp(36).color(message.getColor());
                    viewHolder.messengerImageView.setImageDrawable(iconicsDrawable);
                } else {
                    Glide.with(ChatActivity.this)
                            .load(message.getPhotoUrl())
                            .into(viewHolder.messengerImageView);
                }
            }
        };`

I feel like I am doing something wrong on the onCreateViewHolder method, but I do not know how to fix the problem. Can someone help me?

Most helpful comment

in onStart: adapter.startListening()

All 5 comments

in onStart: adapter.startListening()

@AungThu772 is correct. You could also use setLifecycleOwner(this) option to handle your lifecycle automatically. I would recommend reading the docs.

Thank you @AungThu772 and @SUPERCILEX!

Take a look of code, as I have optimized code and solved this problem.
Here is my solution:
RecyclerviewAdapter is not working with new update of firebase-ui-database to 16.0.1

@AungThu772 is correct. You could also use setLifecycleOwner(this) option to handle your lifecycle automatically. I would recommend reading the docs.

That was a quickest and the best solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akrmn picture akrmn  路  4Comments

dmikesell picture dmikesell  路  3Comments

RedCider picture RedCider  路  5Comments

ghost picture ghost  路  5Comments

judeebene picture judeebene  路  4Comments