Answer the question
In order to leave comments, you need to log in
How to create a variable from the content of an EditText?
Hello! There is a separate Settings activity in which there are only EditText and Button (OK). The idea is this:
- We write something in the EditText
- We press the Button (OK) and here ..... we need to save what we wrote in the EditText as a global variable (sometext).
Those. this variable is needed in MainActivity.
Or this variable can be stored in some other way.
In general, you can store in xml (res/values/settings.xml), but how to store the value from EditText in settings.xml?
Thanks in advance for any suggestions or solutions.
Answer the question
In order to leave comments, you need to log in
There are quite a few ways here. As for the tools of the android itself, 2 things come to mind at once:
1) startActivityForResult (I think it's best for your task) startandroid.ru/ru/uroki/vse-uroki-spiskom/68-urok...
2) SharedPreferences startandroid.ru/ru /uroki/vse-uroki-spiskom/73-urok...
or store the data in a singleton class, or just in a static field
Because preferences must persist between app launches, use SharedPreferences to save preferences .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question