0

I am new to Android, my question is how to retrieve the original value from the activitMain.xml of the android : text (without saving it to a file) I mean that in the original value was android : text="aaa" then it was changed by the user to "bbb" if i do textView.getText I get the current value (bbb) i want to retrieve aaa

Thanks

Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103
RMagen
  • 612
  • 2
  • 9
  • 23

1 Answers1

1

(New answer with more knowledge of question)

Maybe you can do it with Strings.xml??

<string name="player_1">Rahav</string>
<string name="player_2">Martin</string>

EditText in your xml file: android:text="@string/player_1"

Then programatically you can set it to the first player.

yourEditText.setText(getResources().getString(R.string.player_1);
Martin Lund
  • 1,159
  • 9
  • 17
  • My Q is how to get the value with out saving it before...this field is can be changed and saved and then i need to retrieve the original value – RMagen Sep 05 '17 at 09:26
  • Yes but you can save it in a string variable, it is not really saved. You can then do whatever you want with this string whenever you need to get the value of it. The original value will just be held in the string variable. I don't think there is an easier way to easily just capture whatever the original value was. – Martin Lund Sep 05 '17 at 09:37
  • OK - i will explain some mor about the field . lets say i have an app that holds the name of 4 playes -some day player 4 is not playing and player 5 is playing -so i am chaning the name of player4 to player5 (this value is saved so incase the app will crush the data will not be lost ) the day after player 4 is coming so i want to press INIT button to retrieve the defaults name (with out saving it to a file ) just get the value which is currently in the activityMain.xml – RMagen Sep 05 '17 at 11:02
  • 1
    Ah that makes more sense - So you want to be able to assign player 1 = "Rahav", player 2 = "Martin" and so on? And then if let's say Martin wont join, someone else is going to take that place temporary?? You can probably get this by doing shared preferences. Shared preferences are key value pairs: https://stackoverflow.com/questions/23024831/android-shared-preferences-example This way you can do a call to editor.putString("player1","Rahav"); And then when you want to retrieve this again you can do: prefs.getString("player1", null); Hope this works helps you :) – Martin Lund Sep 05 '17 at 11:21
  • thank you BUT again - i know how to save to sharedPreferences i am asking if i can get the defult value from the mainActivtiy.xml some how – RMagen Sep 05 '17 at 11:34
  • Anytime! Glad i could help :) – Martin Lund Sep 05 '17 at 12:36