I’ve created an EditTextPreference and now I want to get the value from any other activity. I’ve been trying a lot of things but I cannot get it working. Where is this value stored? How can I retrieve it?
EDIT: I want to get the value from a different activity, not the Preferences activity.
settings.xml
<EditTextPreference
android:title="EditText1"
android:key="edit1"
android:defaultValue="0"
android:dialogIcon="@drawable/fleetespiar"
android:inputType="number" />
Settings.java (How to do this in a different activity)
Preference edit1= findPreference("edit1");
EditTextPreference editt1 = (EditTextPreference) edit1;
System.out.println(String.valueOf(editt.getText().toString()));
Your value will be stored in a shared preference file.
Check my little example below:
Create a xml directory inside the res directory (resources) of
your android project.
Inside your new xml directory you must create a preference.xml file wich will contains your EditTextPreference.
Now create your Preferences class which extends PreferenceActivity.
Use a SharedPreference object to insert and get your String value.