How to show date in between conversation in recyclerview or in listview

前端 未结 3 367
一整个雨季
一整个雨季 2020-12-31 18:24

How to show date or today , yesterday like text in between conversation

like whatsapp

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 19:07

    You need to create a new ViewHolder for that purpose

    For example:

    // Different types of rows
    private static final int TYPE_ITEM_LEFT = 0;
    private static final int TYPE_ITEM_RIGHT = 1;
    private static final int TYPE_ITEM_DATE_CONTAINER = 2;
    
    public class MyAdapter extends RecyclerView.Adapter {
    class ViewHolder0 extends RecyclerView.ViewHolder {
        // Viewholder for row type 0
    }
    
    class ViewHolder1 extends RecyclerView.ViewHolder {
        // Viewholder for row type 1
    }
    
    class ViewHolder2 extends RecyclerView.ViewHolder {
        // Viewholder for row type 2
    }
    
    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int position) {
         if (viewHolder.getItemViewType() == TYPE_ITEM_LEFT) {
             // Code to populate type 0 view here
    
         } else if (viewHolder.getItemViewType() == TYPE_ITEM_RIGHT) {
             // Code to populate type 1 view here
    
         } else if (viewHolder.getItemViewType() == TYPE_ITEM_DATE_CONTAINER) {
             // Code to populate type 2 view here
    
         }
    }
    

提交回复
热议问题