Skip to content

Simple code to create dates in recyclerView like in chat apps like whatsapp or notifications page like linkedin

License

Notifications You must be signed in to change notification settings

AnyangweChe/Creating-Dates-in-RecyclerView-for-chat

Repository files navigation

Creating-Dates-in-RecyclerView-for-chat

Simple code to create dates in recyclerView like in chat apps like whatsapp or notifications page like linkedin

Before you start, make sure that you updated your Android Studio to latest version. Currently my Android Studio is updated to Android Studio 3.3.2.

Open build.gradle and add recycler view dependency. # com.android.support:recyclerview-v7:28.0.0-alpha-3, com.android.support:recyclerview-v7:28.0.0-alpha-3 # and rebuild the project.

In the MainActivity.java , create the adapter class. The adapter has a constructor used in passing data to the RecyclerView.

Create layout xml called list_item.xml. This layout file renders a single row in recycler view by displaying movie name, genre and year of release.

  1. Now open MainActivity.java and do the below changes. Here, we create another arraylist ArrayList years = new ArrayList(); .We loop through ArrayList year = new ArrayList , add new values to the array and leave the index empty for values that are already in the array.

Create new arraylist years

ArrayList years = new ArrayList(); Loop through arraylist for (String yeas : year) { if (years.contains(yeas)) { years.add(""); } else { years.add(yeas); } }

  1. We then tell our adapter not to display views that don’t have data. We change the value we are passing to the constructor from year to years. From // Initialise adapter with constructor values ContentAdapter mAdapter = new ContentAdapter(title,genres,year,date); To

ContentAdapter mAdapter = new ContentAdapter(title,genre,year,date);

Condition statement in adapter for (String yeas : year) { if (years.contains(yeas)) { years.add(""); } else { years.add(yeas); } }

Now if you run the app, you can see the movies displayed in a list manner.

recycler view dates

About

Simple code to create dates in recyclerView like in chat apps like whatsapp or notifications page like linkedin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages