How can I make a list of items appear daily in a recycler view in android?

41 Views Asked by At

I want them to represent a list of daily habits, which can be checked of during the day, and will appear again the next day. In what direction should I research this?

1

There are 1 best solutions below

0
RamammDev On

There is 2 way to do this. Either you store your daily habits in database and fetch it from there or store your daily habits in SharedPreferences and get your data inside onCreate in Activity.

To save your data inside SharedPreferences you can use code below:

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("name", "Alex");
editor.putInt("habit", "Start Coding");
editor.apply();

And to retrieve data you should use code below inside onCreate:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String name = prefs.getString("name", "Empty");//"Empty" is the default value.
int idName = prefs.getInt("habit", "Empty");