My app contains shared preferences, so in my "Settings-Menu" I can select an item from a list.
In another java file I want to access the value of the selected item.
I failed passing the integer-value through an intent, because the integer is declared in private static, private boolean, and Android Studio tells me, it cannot be refferenced from a static content.
So how can I receive my value from this integer? Thanks in advance :).
Edit: firstival, thanks a lot for that many answers! But as I'm not that much into java I wasn't able to follow your instructions, so I'm going to depict my problem closer.
I'm using androids template "Settings-Activity". In my strings.xml I've got
<string name="Values">Values</string>
<string-array name="pref_example_list_titles">
<item>A</item>
<item>B</item>
<item>C</item>
</string-array>
<string-array name="pref_example_list_values">
<item>01</item>
<item>02</item>
<item>03</item>
</string-array>
In my SettingsActivity.java
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
{...}
In another java file, a fragment "FirstFragment.java I finally want to assign the value from pref_example_list_values to a new integer, called "Vallue2".
So could you please explain me, how I do this, bc I couldn't follow your explainations. Thanks a lot!