Failed To Show The Grouping Date View For The Chat Messages In The Recyclerview Android
How can I make the grouping and show the date view in my app. I am using recyclerview and java to show this messages Structure: --------- **12-04-2021** ---------- --Leftsideme
Solution 1:
As minemsg
is either true or false, the code returning DATE_VIEW_TYPE
would never be reached. i.e., follow this pseudo-code:
boolean minemsg = true;
if (minemsg)
{
return;
}
if (!minemsg)
{
return;
}
// anything after this would never be reached!, as minemsg is either true or false.
Its not clear from your question what minemsg
is, please try changing the order of evaluation as follows:
@Overridepublic int getItemViewType(int position) {
Message message = (Message) msgDtoList.get(position);
// check for date record firstif (message.getmSentTime() != "") { // here the message senttime is always print inside this condition. But failed to show the view in the app.return DATE_VIEW_TYPE;
}
if (minemsg) {
// If the current user is the sender of the messagereturn VIEW_TYPE_MESSAGE_SENT;
}
if (!minemsg) {
// If some other user sent the messagereturn VIEW_TYPE_MESSAGE_RECEIVED;
}
return0;
}
EDIT: After reading your comments below, your problems are much deeper, you're trying to display a single ArrayList
of messages with section/group headers.
This is beyond the scope of the question you asked, and appears to already have answers, e.g.:
How to implement RecyclerView with section header depending on category?
Solution 2:
Try this:
@Overridepublic int getItemViewType(int position) {
Message message = (Message) msgDtoList.get(position);
// Since message can either be "mine" or "not mine" lets check the sent time first, and return the DATE_VIEW_TYPE to avoid dead codeif (message.getmSentTime() != "") { // here the message senttime is always print inside this condition. But failed to show the view in the app.return DATE_VIEW_TYPE;
}
if (minemsg) {
// If the current user is the sender of the messagereturn VIEW_TYPE_MESSAGE_SENT;
}
if (!minemsg) {
// If some other user sent the messagereturn VIEW_TYPE_MESSAGE_RECEIVED;
}
// Everything below is "dead, unreachable code" due to booleans being either true or falsereturn0;
}
Post a Comment for "Failed To Show The Grouping Date View For The Chat Messages In The Recyclerview Android"