A
A
Aidar2015-02-09 02:26:31
Android
Aidar, 2015-02-09 02:26:31

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

3 answer(s)
A
Andriy Biskup, 2015-02-09
@AndriyTheProgrammer

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

F
frakcstran, 2015-02-09
@frakcstran

Because preferences must persist between app launches, use SharedPreferences to save preferences .

R
Rikcon, 2015-02-09
@Rikcon

In Sharpe, I used a static class for this, but by googling I realized that Java doesn’t have a static class especially.
I came across here stackoverflow.com/questions/7486012/static-classes...
Maybe it will help somehow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question