I'm using startActivity(new Intent(this, SettingsActivity.class))
from an Activity
to call the PreferenceFragment
of my app when a certain user interaction is required to be performed into the preferences.
I think would be good to scroll down to reach the involved preference.
I found solutions about how to scroll views into ScrollView
s and ListView
s, but nothing related to PreferenceFragment
s.
My preferences look like:
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
public static class SettingsFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {
//preferences:
private Preference p
// [...]
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
//preference click listeners...
p = (Preference) findPreference("PR_NAME");
p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
// ...
return true;
}
});
// [...]
}
}
}
Thanks for any suggestion
To scroll in PreferenceScreen (Setting/Preferences), Use this for Android API 24.1.+ or with androidX API
public void scrollToPreference (String key)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With