I need to get value from PreferenceFragment to SplashActivity. How can i do it?
public class SettingsFragment extends PreferenceFragment {
public String cityToLoad;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
ListPreference city = (ListPreference) findPreference("city");
city.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
cityToLoad = newValue.toString();
return true;
}
});
}}
my preferences.xml contains only ListPreference.
You don't have onchange event in list preference. For More http://developer.android.com/reference/android/preference/PreferenceFragment.html
And if you are just using preference tag then you can try below code.
city.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
Intent newScreen = new Intent(getActivity(), SecondActivity.class);
newScreen.putExtra("Data", data);
startActivity(newScreen);
return true;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.