android - How to load strings from sharedpreferences in EditText -
I am very new to this and hate to add so much code, but I have spent so much time on it that I Out of the option I have an activity / page which saves some user department. Now, I am trying to save these details so that the next time they open the activity / page, the data will be shown.
I have tried to start the loaded processes in the current method. However, this is not working, and if I go back to the previous page and retrieve this activity then all of it has gone back. The answer to the code will be greatly appreciated.
Java:
Public class increases my_settings activity {edit test name; Edit text email; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.activity_my_settings); Name = (edit text) search viviId (ridname); Find Email = (Edit Text) VVBIID (RID. Mail); LoadSavedPreferences (); } Public Zero Save (see view) {shared options user details = references received ("user description", reference. MODE_PRIVATE); SharedPreferences.Editor Editor = userDetails.edit (); Editor.putString (. "StoredName", name.getText () toString ()); Editor.putString (. "StoredEmail", email.getText () toString ()); Editor.commit (); Toast. Make text (this, "the data was saved successfully", toast.LnnHH_LOG). Show (); } Separation from private zeros load () {shared project usages = referrals.nager.get default shared references (this); String tempName = userDetails.getString ("stored name", "name"); // (key, default) string tempEmail = userDetails.getString ("storedEmail", "email address"); Name.setText (tempName); Email.setText (tempEmail); }} The XML code looks like this
& lt; RelativeLayout xmlns: android = "http://schemas.android.com/apk/res / Android" xmlns: device = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height = "Match_parent" Android: paddingLeft = "@ Dimen / activity_horizontal_margin" Android: paddingRight = "@ Dimen / activity_horizontal_margin" Android: paddingTop = "@ Dimen / activity_vertical_margin" Android: paddingBottom = "@ Dimen / activity_vertical_margin" tool: reference = "com. Example.jesper.im_ok.my_settings "Android: clickable =" false "& gt; & Lt; TextView android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" android: text = "Please contact details recorded here:" android: id = "@ + id / SETTINGS_TITLE" Android: layout_alignParentTop = "true" Android: Layout_centerHorizontal = "True" Android: Text Size = "20sp" Android: Clickable = "False" /> & Lt; EditText Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" android: text = "Contact Name" Android: EMS = "10" android: id = "@ + id / name" Android: Layout_below = "@ + Id / Settings_title "android: layout_centerHorizontal =" true "/> & Lt; EditText Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" Android: inputType = "textEmailAddress" android: text = "email address" Android: EMS = "10" android: id = "@ + id / Email" Android: Layout_belo = "@ + ID / Name" Android: Layout_Linign = "@ + ID / Name" Android: layout_alignStart = "@ + id / name" /> & Lt; / RelativeLayout & gt; After
-
In the save mode, the GetSharedPreferences ("UserDetails", Context.MODE_PRIVATE); which user made SharedPreferences table and -
When you defaultSharedPreferences accessing data which are trying to get the values are the default one provided by Android false
try it loadSavedPreferences
SharedPreferences userDetails = this.getSharedPreferences ( "UserDetails", Context.MODE_PRIVATE). Hope it helps !!
Comments
Post a Comment