java - android Preferences findPreference Non-static method cannot be referenced from a static context -
i'm reading preferences info in other activity (public class sample extends baseportraitactvity
).
i need not value, title.
code i've managed write:
public void onstart() { super.onstart(); sharedpreferences prefs = preferencemanager .getdefaultsharedpreferences(getbasecontext()); string mparamvalue = prefs.getstring("samplekey", "default"); string t = preferencefragment.findpreference(settingsactivity."samplekey").gettitle(); }
so far found value use getstring
key parameter , works. title method gettitle
has no parameters, tried above. however, studio says "non-static method 'findpreference(java.lang.charsequence)' cannot referenced static context".
how title in other activity (it should in correct language set in xlm files)?
p.s. still cannot grasp static
in java. why onstart considered static
?
preferences database stores key-value combination. other info in xml files.
e.g. in preferences.xls: android:title="@string/settings_user_name"
in strings.xls: <string name="settings_user_name">your name</string>
in java use: getresources().getstring(r.string.settings_user_name)
Comments
Post a Comment