Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6816305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:54:35+00:00 2026-05-26T20:54:35+00:00

I have PreferenceActivity with plenty of PreferenceCategories defined in it. If I have the

  • 0

I have PreferenceActivity with plenty of PreferenceCategories defined in it. If I have the android:key of a given category.

Is it possible programmatically to scroll the Activity to this category?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:54:36+00:00Added an answer on May 26, 2026 at 8:54 pm

    You can iterate through the preferences in the activity like this:

    PreferenceScreen screen = getPreferenceScreen();
    int i;
    for(i = 0; i < screen.getPreferenceCount(); i++) {
       String key = screen.getPreference(i).getKey();
    
       // be careful, because key will be null if no android:key is specified
       // (as is often the case for PreferenceCategory elements)
       if("myKey".equals(key))
          break;
    }
    
    // PreferenceActivity extends ListActivity, so the ListView is accessible...
    getListView().setSelection(i);
    

    Tested out with Android SDK 14 and it works fine.

    Caution though, calling getListView().setSelection(i) inside onCreate or onResume has no effect. It has to be called after the activity is drawn.

    The getPreferenceCount() method counts all PreferenceCategories and their nested preferences. Not sure what it does for PreferenceScreens, although I’m sure a little experimentation there would be revealing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read http://developer.android.com/reference/android/app/Activity.html but I have a question about PreferenceActivity lifecycle: Does a PreferenceActivity
I have 1 PreferenceActivity in preferences.xml is <CheckBoxPreference android:id=@+id/pushCB android:checked=true android:defaultValue=true android:key=PushService android:summary=Set to
I have used PreferenceActivity to have preference in my android application. I want one
i have a strange (?) error in my android application. I have defined some
I have this onClickListener in onCreate method of my PreferenceActivity, but it gives me
I have a class extending PreferenceActivity: public class PreferenceActivity extends android.preference.PreferenceActivity { @Override protected
I have an activity which extends PreferenceActivity. I'm loading preferences from the xml file.
I have the same problem like this question: Custom title bar in PreferenceActivity? After
I have PreferenceActivity with some sample content: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=First
I have created activity which extends preferenceActivity. In that activity I have opened custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.