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 4005124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:21:22+00:00 2026-05-20T08:21:22+00:00

I have a ListPreference which I populate dynamically when clicking on the list to

  • 0

I have a ListPreference which I populate dynamically when clicking on the list to display it.
The population works fine, but the values I populate is not displayed until the next time i click to open the list, but instead the values from the xml-file is displayed the first time. It feels like the list has already been populated before the onPreferenceClick is called. How can I refresh the list probably? I want to populate the list before every click in the list.

     /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.preferences);

  // Get preferences.
  prefs = PreferenceManager.getDefaultSharedPreferences(this);
  screen = getPreferenceScreen();

  // Install on-click listener for calendars.
  screen.findPreference("googleCalendars").setOnPreferenceClickListener(onSelectCalendarsClick);
 }

 /**
  * We had a click on select calendars.
  */
 public OnPreferenceClickListener onSelectCalendarsClick = new OnPreferenceClickListener() {
  public boolean onPreferenceClick(Preference pref) {

   final String username;
   final String password;
   final String list;

   if (pref == findPreference("googleCalendars")) {
    username = prefs.getString("googleUsername", "");
    password = prefs.getString("googlePassword", "");
    list = "googleCalendars";
   }
   else {
    Log.d(TAG, "onSelectCalendarsClick.run(),unknown list clicked: " + pref.getTitle());
    return false;
   }

   // Show process dialog while updating.
      final ProgressDialog dialog = ProgressDialog.show(Preferences.this, "", "Fetching calendars, please wait...", true);
      // Show dialog, non cancelable.
      dialog.setCancelable(false);
       dialog.show();

   // Create new updater thread.
   new Thread(){
    public void run() {
     Log.d(TAG, "onSelectCalendarsClick.run(), new thread. Fetching calendars...");
     // Get calendars
     // Create API.
     CalendarApi calendarApi = new CalendarApi(prefs.getBoolean("debugFakeCalendar", false));
     GetCalendarsResponse response = calendarApi.GetCalendars(username, password);
     Log.d(TAG, "onSelectCalendarsClick.run(), new thread. Done!");
     // Create new message and send it.
     Message msg = new Message();
     Bundle bundle = new Bundle();
     bundle.putString("list", list);
     msg.setData(bundle);
     msg.obj = response;
     getCalendarsHandler.sendMessage(msg);
     // cancel dialog.
     dialog.cancel();
    }
   }.start();

   return false;
  }

 };

 /**
  * Handler for processing response from getCalendars.
  */
    Handler getCalendarsHandler = new Handler() {
      @Override
      public void handleMessage(Message msg) {
        super.handleMessage(msg);


        // We have a new message.
        GetCalendarsResponse response = (GetCalendarsResponse)msg.obj;
        Bundle bundle = msg.getData();

        // Null?
        if (response == null || response.calendars == null) {
          Log.d(TAG, "getCalendarsHandler.handleMessage(): response is null.");
          return;
        }

         // Fetch.
        ListPreferenceMultiSelect list = (ListPreferenceMultiSelect)screen.findPreference(bundle.getString("list"));
        if (list != null) {
          // Ok response.
          list.setEntries(response.getEntries());
          list.setEntryValues(response.getEntryValues());
        }

        // Display list preference.
        list.getDialog().show(); 
      }
    };
}
  • 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-20T08:21:23+00:00Added an answer on May 20, 2026 at 8:21 am

    The documentation for setEntries states that the settings will be shown in the subsequent dialogs.

    Android populates the ListPreference as soon as OnClickPreference is fired, and anything you do after that will be shown in the subsequent dialogs.

    You might want to populate it beforehand than refresh it after it is shown. Best way to populate it beforehand is to populate the ListPreference in onCreate, and let it sit there to be shown.

    Hope this helps

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

Sidebar

Related Questions

I have a simple preference (not EditText preference or ListPreference). I have a method
i have a input tag which is non editable, but some times i need
I have a ListPreference which look something like this: <ListPreference android:title=Choose item android:summary=... android:key=itemList
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a settings menu that pops up and in it is a ListPreference
I have these strings in an ArrayList of String in no particular order but
Any idea on implementing a multi-select (check boxes) ListPreference on Android? Would I have
I have found this example on StackOverflow: var people = new List<Person> { new
I have a login.jsp page which contains a login form. Once logged in the
I don't understand what's going on here. I have a ListPreference with the entries

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.