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

  • Home
  • SEARCH
  • 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 7799501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:19:50+00:00 2026-06-02T00:19:50+00:00

I need dynamic entries in ListPreference so I can not use conventional way of

  • 0

I need dynamic entries in ListPreference so I can not use conventional way of XML setup of which there are tons of materials online. So far I have following setup as you can see bellow. Problem is that when I run this I see dialog with title and message but no entries are showed even though I know that entries and values are not empty (I know that my entries and values are same but I would get error if I didn’t supplied entries)


my.preference.DynamicPreference
            android:title="@string/date_format"
            android:dialogMessage="@string/profile_info_date_format"
            android:entryValues="@array/date_format_values"
            android:entries="@array/date_format_values"

public class DynamicPreference extends ListPreference {
    private int index;

    public DynamicPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DynamicPreference(Context context) {
        super(context);
    }

    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
        builder.setTitle(getTitle());
        builder.setMessage(getDialogMessage());
        builder.setSingleChoiceItems(entries(), -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        super.onPrepareDialogBuilder(builder);
    }

    @Override
    public void setEntries(CharSequence[] sequence) {
        CharSequence[] entries = listObjects().toArray(new CharSequence[listObjects().size()]);
        super.setEntries(entries);
    }

    @Override
    public void setEntryValues(CharSequence[] sequence) {
        CharSequence[] values = getContext().getResources().getStringArray(R.string.date_format);
        super.setEntryValues(values);
    }
}
  • 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-06-02T00:19:52+00:00Added an answer on June 2, 2026 at 12:19 am

    The android:dialogMessage was good starting point here, thank you @MH. for spotting it. Bellow is simple setup I ended with, I hope someone may find it helpful

    <my.preference.DynamicPreference
            android:title="@string/local_time"
            android:key="profile_info_local_time"
            />
    
    
    public class DynamicPreference extends ListPreference {
    
    
        public DynamicPreference(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public DynamicPreference(Context context) {
            super(context);
        }
    
        @Override
        protected View onCreateDialogView() {
            ListView view = new ListView(getContext());
            view.setAdapter(adapter());
            setEntries(entries());
            setEntryValues(entryValues());
            setValueIndex(initializeIndex());
            return view;
        }
    
        private ListAdapter adapter() {
            return new ArrayAdapter(getContext(), android.R.layout.select_dialog_singlechoice);
        }
    
        private CharSequence[] entries() {
            //action to provide entry data in char sequence array for list
        }
    
        private CharSequence[] entryValues() {
            //action to provide value data for list
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to add multiple entries in symfony to database? I use
I need to have a dynamic URL preferably from a Test Class. Can any
I am building a dynamic form in that the user can keep adding entries
I need to track which instance created another instance. It's an instancing hierarchy not
I am making an iphone application in which there is use of database. But
For a project I need a dynamic way of loading partial views, preferably by
I need to used dynamic order query in mysql and i have successfully achieved
I need to add dynamic controls and get its values in my asp.net mvc
I need to build a dynamic linq query with or operators. I have seen
I need to create a dynamic array in Java, but the values type differ

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.