https://www.google.com/search?q=message+image+on+last&sxsrf=ALeKk01qNrLQ61yRXCMSPRxyNaoI0MF_kA:1605295893515&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjj2veboYDtAhWeIbcAHebnB4QQ_AUoAXoECAwQAw&biw=1366&bih=657#imgrc=wzgnznL_g7kUsM
我只想在同一个人的每条连续消息的最后一条消息上显示上面链接中显示的个人资料图像。请帮我做这个。
我已经尝试了很多方法,但我不知道隐藏顶部图像的可见性
if (position > 0) {
if (messageList.get(i).getFrom.equalsIgnoreCase(messagesList.get(position - 1).getFrom()))
{
viewHolder.mProfileImage.setVisibility(View.INVISIBLE);
}
else
{
viewHolder.mProfileImage.setVisibility(View.VISIBLE);
}
}
else
{
viewHolder.mProfileImage.setVisibility(View.VISIBLE);
}
我使用了上面的代码,得到了如下所示的结果https://i.stack.imgur.com/92SUb.jpg链接有了这个代码,我可以隐藏除第一个图像之外的所有图像。你能告诉我如何隐藏最上面的信息图片,而不是最后一个条纹吗。
在我的回答中,我不得不假设一些事情。即
- messageList是所有消息的列表。而不是仅连续/连续消息的列表
- 您需要显示发送者和接收者的个人资料图像
- 并且您只想显示最后一条连续消息的profileImage
所以,这里是你应该做的。
int length = messageList.lenght; //getTotalLenght;
String fromCurrent = messageList[position].getFrom(); //getFrom of current message being painted or shown
String fromNext = fromCurrent; //next message is set to current by default, to avoid error
if(length > postition+1) {
fromNext = messageList[position+1].getFrom(); //if there is next message then get its sender but if it is the last message then nextSender and currentSender are same as I set its default value to the currentSender.
}
console.log("TAG", "FromNext: " + fromNext);
console.log("TAG", "FromCurrent: " + fromCurrent);
if(!fromCurrent.equals(fromNext)) { //checking if last message or not
viewHolder.mProfileImage.setVisibility(View.VISIBLE);
}
else {
viewHolder.mProfileImage.setVisibility(View.INVISIBLE);
}