Question: ( give code to put into android studio using java and xml ) Application Title: Personal Diary App Purpose: To demonstrate the capabilities of Android's
give code to put into android studio using java and xml Application Title: Personal Diary App
Purpose:
To demonstrate the capabilities of Android's SharedPreferences by creating an application where
users can write and save personal diary entries.
Features and Algorithms:
App Structure:
The application should feature a simple and userfriendly interface for writing and viewing diary entries.
Implement RecyclerView for displaying a list of saved diary entries.
Diary Entry Creation and Display:
Users should be able to create new diary entries with a title and content.
Display a list of entry titles on the main screen. Selecting a title should display the full diary entry.
Use of SharedPreferences:
Utilize SharedPreferences to save and retrieve diary entries.
Demonstrate the use of SharedPreferencesEditor for writing data and SharedPreferences for reading data.
Each diary entry title and content should be stored as a separate preference.
Editing and Deleting Entries:
Provide options for users to edit or delete existing entries.
Reflect these changes immediately in the SharedPreferences and update the UI accordingly.
User Interface:
Design the app to be intuitive and easy to navigate.
Consider implementing a floating action button for adding new entries.
Use a clean and minimalist design to keep the focus on the content. To save:
Assume 'saveButton' is your button and 'nameEditText' is your EditText
saveButton.setOnClickListenernew View.OnClickListener
@Override
public void onClickView v
String name nameEditText.getTexttoString;
Getting SharedPreferences
SharedPreferences sharedPreferences getSharedPreferencesMySharedPrefs MODEPRIVATE;
Opening the SharedPreferences editor to write data
SharedPreferences.Editor editor sharedPreferences.edit;
Storing the name with a key "userName"
editor.putStringuserName name;
Applying the changes
editor.apply;
Toast.makeTextMainActivitythis, "Name saved!", Toast.LENGTHSHORTshow;
;
To retrieve:
Getting SharedPreferences
SharedPreferences sharedPreferences getSharedPreferencesMySharedPrefs MODEPRIVATE;
Retrieving the value using the key. The second parameter is a default value if the key doesn't exist
String name sharedPreferences.getStringuserName "Default Name";
Now 'name' contains the stored value or "Default Name" if nothing was stored
Note: SharedPreferences is accessible throughout the application
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
