Установить дату в качестве заголовка в RecyclerView - PullRequest
0 голосов
/ 18 июня 2020

У меня есть RecyclerView, в котором я показываю уведомления. В TextView я хочу иметь возможность отображать дату уведомления в виде заголовка. Так, например,

  • Все уведомления, полученные сегодня, будут в --Сегодня -.

  • Все уведомления со вчерашнего дня будут в - -Вчера -.

  • А для старых уведомлений я хочу просто показать дату.

Это то, что я загружаю the recyclerview

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
xmlns:card_view="http://schemas.android.com/apk/res-auto">


<de.hdodenhof.circleimageview.CircleImageView
    android:id="@+id/notification_item_profile_image"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_margin="10dp"
    android:src="@drawable/profile"/>

<TextView
    android:id="@+id/notification_item_username"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toStartOf="@id/notification_item_post_image"
    android:layout_toEndOf="@id/notification_item_profile_image"
    android:text="User name"
    android:textSize="14sp"
    android:layout_marginTop="10dp"
    android:layout_marginStart="5dp"
    android:textColor="@color/colorPrimary"
    />
<TextView
    android:id="@+id/notification_item_notification"
    android:layout_width="match_parent"
    android:layout_toStartOf="@id/notification_item_post_image"
    android:layout_height="wrap_content"
    android:layout_below="@id/notification_item_username"
    android:layout_toEndOf="@id/notification_item_profile_image"
    android:text="Notification"
    android:layout_marginTop="5dp"
    android:layout_marginStart="5dp"
    android:textSize="14sp"
    android:textColor="@color/colorPrimary"
    />

<ImageView
    android:id="@+id/notification_item_post_image"
    android:layout_width="50dp"
    android:visibility="invisible"
    android:layout_height="50dp"
    android:layout_alignParentEnd="true"
    android:layout_centerInParent="true"
    android:layout_marginEnd="10dp"
    />

Примерно так enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...