ChatBot
ChatBot copied to clipboard
Chat messages do not show.
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);
}
}_
};
Have u solved the issue Messages are displayed ???
In the update code u forget to place ref.child("chat") please check it
@timmy9ja @Uday2024 There is no problem in the code. The problem is occurring due to my firebase project. As it is open to everyone people try new things which usually changes the data structure. I would recommend you to make your own firebase Project. Follow the firebase guide to use adapter as there are many new changes. PS: Sry for the delay answer.
I am getting app stopped responding error.App is not opening,
@timmy9ja @Uday2024 There is no problem in the code. The problem is occurring due to my firebase project. As it is open to everyone people try new things which usually changes the data structure. I would recommend you to make your own firebase Project. Follow the firebase guide to use adapter as there are many new changes. PS: Sry for the delay answer.
Bro, there's some issue with the recycler view. It does not display the chat messages. I have linked my code to my firebase, where I could obtain the chat messages.
It took me three days to resolve the errors The code is completely obsolete according to new Android standards. It's better to code everything all together again. And if you have migrated to androidx from android, you have my blessings.
Anyways could the chat messages not being displayed work out for anyone, given it is being saved in my database but not showing anything in the layout. I have even asked a doubt regarding it here: https://stackoverflow.com/questions/56860460/not-able-to-properly-show-chat-send-by-user-and-receiver-on-screen Please help!
Hi @Raghuram-Veeramallu, @rohetoric you can check the answer here https://stackoverflow.com/questions/56860460/not-able-to-properly-show-chat-send-by-user-and-receiver-on-screen/61366603#61366603