-2

I have a registration page which contains edit texts and 1 dropdown. After successful registration,I am navigated to another pages.But I have a option to edit my account at any time.By clicking edit button I am able to go back to registration page,but not able to see the details that I have previously entered.How can I achieve the same?

Thanks in advance.

Amit Nair
  • 295
  • 2
  • 5
  • 21

2 Answers2

0

Either you can save the related values to sharedpreferences or database and fetch them. Or you can also pass values by intent putExtra.

Follow below link for using intent putextra

https://stackoverflow.com/a/5265952/3975838

For storing to database you can see tutorial on

http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

Finally sharedprefences. Below answer shows how to store and retrieve data

https://stackoverflow.com/a/3624358/3975838

Community
  • 1
  • 1
Zahan Safallwa
  • 3,880
  • 2
  • 25
  • 32
0

You can use SharedPreferences in order to store the information provided when registering. like this:

    SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("prefs",MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("username", "John");
    .
    .
    editor.apply();

Whenever you want to recover the informations for modification, you use

  sharedPreferences.getString("username","default");

Or you can apply it for example to the editText:

 editText.setText(sharedPreferences.getString("username","default"));

Hope it helps :)

yanisB
  • 89
  • 1
  • 11
  • I am already storing the values using stored prefernce. But how to store the values to the edit text fields in registration acivity as m edit button is in another activity – Amit Nair Oct 14 '15 at 21:19
  • All activities within you application have access to the same sharedpreferences, i.e. you can store the information in registration activity, and read them in the modification activity, provided that you create sharedpreferences object with the same name, in my case: "prefs" like this: ` SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("prefs",MODE_PRIVATE);` In both activities, and should work. – yanisB Oct 14 '15 at 21:29
  • Yanis,My doubt is how to set the shared pref value to the edittext on button click as my buton is in another fragment and edit text is in another fragment.. – Amit Nair Oct 15 '15 at 11:08
  • Following is the code I have tried final SharedPreferences pref = getActivity().getSharedPreferences("userPref", 0); (Stores the sharedpref value). and on Buttonclick full_name.setText(pref.getString(PanigoConstants.USER_NAME,null)); where full_name is full_name= (EditText) rootView.findViewById(R.id.reg_fullname); – Amit Nair Oct 15 '15 at 11:23
  • Error I am getting is java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference – Amit Nair Oct 15 '15 at 11:26
  • try applying setText in the onStart() of the edittext fragment. probably the NullPointerException is caused because you try to modify edittext before its creation. tell me if it works. – yanisB Oct 15 '15 at 13:50
  • Hi yanis,I tried it in the onResume method of the edit text fragment.It worked for me..Thanks a lot for your support..:) – Amit Nair Oct 16 '15 at 02:50
  • But a new problem I am facing is,edited values are not getting stored to the server..But getting stored to the shared preference. – Amit Nair Oct 16 '15 at 04:43
  • If it works mark the answer as accepted to help others...thanks. when you say:"...are not getting stored to the server". where do you want to store the values? which server do you mean?.. – yanisB Oct 16 '15 at 09:17