Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create section header listing like whatsapp?

I'm developing chat application and i've already design dummy chat history.But i'm stuck at how to group messages according to it's date and when we scroll it down,date indicator stick at the top position just like whats app. can you just show me the way, how can i achieve that? I've attached some screenshot below to elaborate my question.

![enter image description here

like image 795
Tejas Pandya Avatar asked Oct 28 '16 06:10

Tejas Pandya


1 Answers

See this image

Put your header in your custom lisview adapter layout and check everytime your current message date and previous message date. If date is same then hide your header otherwise show your header. See below:

 holder.tvDate.setText(chatMessage.getDate());
    if (position > 0) {
        if (chatMessages.get(position).getDate().equalsIgnoreCase(chatMessages.get(position - 1).getDate())) {
            holder.header.setVisibility(View.GONE);
        } else {
            holder.header.setVisibility(View.VISIBLE);
        }
    } else {
        holder.header.setVisibility(View.VISIBLE);
    }
like image 118
Krupa Kakkad Avatar answered Oct 21 '22 12:10

Krupa Kakkad