I have an editText (R.id.editText1). But when i exit the activity and restart it, the text is gone. So i thought that i make an option menu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_SAVE, 开发者_高级运维0, "Save");
menu.add(1, MENU_GET, 1, "Get");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_SAVE:
Here i must save the editText1
return true;
case MENU_GET:
Here i must get the editText1 that i have saved
return true;
}
return false;
But i don't now how to save an editText and how to load it. I hope you can help me, because i'm newbe to android.
Gaauwe
Edit:
I found the answer on my own. If you have also problems you can go to: http://www.edumobile.org/android/android-beginner-tutorials/state-persistence/
Gaauwe
Try using a SharedPrefrences to save the value in an edittext.
Depends on how long you want to persist the data and how big the text is. Checkout this page on Android.com
http://developer.android.com/guide/topics/data/data-storage.html
SharedPrefrences is an easy way to do this.
精彩评论