Skip to content

Chat messages do not show. #3

@ghost

Description

Hi Divyanshu,
A great job on writing this code for the chatbot. Helped me a lot. I've got a little problem on my end. The chat messages do not show on the app but when I check my training log for my dialog flow agent, the training messages I put from the app appear there. I think it has something to do with the recycler adapter. Could you check and let me know?

Also, how do I fix the memory leak warning in the Async task section of the code on MainActivity.java?

NOTE: I update all the firebase libraries to the latest and update the changes in code functions as suggested in their documentation.

Below is my updated code

This is your original code
_adapter = new FirebaseRecyclerAdapter<ChatMessage, chat_rec>(ChatMessage.class,R.layout.msglist,chat_rec.class,ref.child("chat")) {
@OverRide
protected void onBindViewHolder(chat_rec viewHolder, ChatMessage model, int position) {

            if (model.getMsgUser().equals("user")) {


                viewHolder.rightText.setText(model.getMsgText());

                viewHolder.rightText.setVisibility(View.VISIBLE);
                viewHolder.leftText.setVisibility(View.GONE);
            }
            else {
                viewHolder.leftText.setText(model.getMsgText());

                viewHolder.rightText.setVisibility(View.GONE);
                viewHolder.leftText.setVisibility(View.VISIBLE);
            }
        }
    };_


    **My Update Code begins here**
    _FirebaseRecyclerOptions<ChatMessage> options =
            new FirebaseRecyclerOptions.Builder<ChatMessage>()
                    .setQuery(ref, ChatMessage.class)
                    .build();

    adapter = new FirebaseRecyclerAdapter<ChatMessage, chat_rec>(options) {

        @NonNull
        @Override
        public chat_rec onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.msglist, parent, false);
            return new chat_rec(view);
        }

        @Override
        protected void onBindViewHolder(@NonNull chat_rec holder, int position, @NonNull ChatMessage model) {
            if (model.getMsgUser().equals("user")) {
                holder.rightText.setText(model.getMsgText());
                holder.rightText.setVisibility(View.VISIBLE);
                holder.leftText.setVisibility(View.GONE);
            }
            else {
                holder.leftText.setText(model.getMsgText());
                holder.rightText.setVisibility(View.GONE);
                holder.leftText.setVisibility(View.VISIBLE);
            }
        }_
    };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions