2

In my app I have a Button that you press and I want it to open up my Settings screen (normally accessed with the PreferenceFragment that pulls from the preferences.xml file) and scroll to a specific Category. Is this possible in Android?

KaliMa
  • 1,970
  • 6
  • 26
  • 51
  • See this: http://stackoverflow.com/questions/20407373/is-it-possible-to-auto-scroll-down-a-preferencefragment-to-a-desired-settings – adhirajsinghchauhan Dec 13 '16 at 18:05
  • 1
    use this https://developer.android.com/reference/androidx/preference/PreferenceFragmentCompat.html#scrollToPreference(androidx.preference.Preference) – Elias Fazel Jan 04 '20 at 09:14

2 Answers2

0

You can use the built in function scrollToPreference which will scroll to any section you provide. Mind you depending on what happens on your settings screen you may want to play around with postDelay and wait for everything to have been laid out.

slott
  • 3,266
  • 1
  • 35
  • 30
-1

In scrollView You can use:

mScrollView.post(new Runnable() { 
    public void run() { 
         mScrollView.scrollTo(0, mScrollView.getBottom());
    } 
});

or

mScrollView.post(new Runnable() { 
    public void run() { 
         mScrollView.scrollTo(5, 10);
    } 
});

If you want to go to a Preference screen, you can use

Intent i = new Intent(MainActivity.this, PreferenceActivity.class);
startActivity(i);
qubuss
  • 268
  • 3
  • 12
  • This isn't exactly what I am asking. I am asking how to get access to the preference list / scroll to a particular category. I already know how to get to the screen using an intent (my Activity holds a PreferenceFragment), but I don't know how to get the list and scroll to the spot. – KaliMa Nov 28 '16 at 19:41
  • so sorry :), try read this [android tutorial ](https://developer.android.com/guide/topics/ui/settings.html) – qubuss Nov 28 '16 at 19:49
  • 1
    This doesn't seem to mention how to get access to the list – KaliMa Nov 28 '16 at 19:53