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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:53:49+00:00 2026-06-11T08:53:49+00:00

I have a PreferenceScreen made with a custom ListPreference and a CheckBoxPreference. This is

  • 0

I have a PreferenceScreen made with a custom ListPreference and a CheckBoxPreference. This is the XML called ‘pref_screen_custom.xml’:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- My custom preference type.  This just replaces the actual widget
     portion of the preference, if the whole preference wanted to be
     replaced we would use the layout attribute instead of the widgetLayout
     attribute. -->
<com.pref_002.Pref002
        android:key="my_preference"
        android:title="Title: Pref002"
        android:summary="Summary: summary"
        android:defaultValue="-1"
        android:entries="@array/pref002_list_ent"
        android:entryValues="@array/pref002_list_vals"
        android:dialogTitle="title" />

<CheckBoxPreference
        android:key="advanced_checkbox_preference"
        android:title="Title: checkbox preference"
        android:summaryOn="On checkbox" 
        android:summaryOff="Off checkBox" />
</PreferenceScreen>

The XML that holds the array for the preferences is (array.xml):

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="pref002_list_ent">
        <item>T</item>
        <item>V</item>
        <item>S</item>
    </string-array>
    <string-array name="pref002_list_vals">
        <item>10</item>
        <item>8</item>
        <item>6</item>
    </string-array>

</resources>

The .java for the PreferenceScreen, called PrefCustom002Activity.java, is:

package com.pref_002;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class PrefCustom002Activity extends PreferenceActivity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.pref_screen_custom_001);
    }
}

And the class that extends ListPreference, called ‘Prefs002.java’, is:

package com.pref_002;

import android.content.Context;
import android.preference.ListPreference;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

public class Pref002 extends ListPreference
{
    // Constructor called by the inflater
    public Pref002(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }
    @Override
    protected View onCreateView(ViewGroup parent)
    {
        // New Layout that will contain the default loaded View from ListPreference
        // plus a new one (a Button)
        LinearLayout newLayoutParent = new LinearLayout(getContext());
        newLayoutParent.setOrientation(LinearLayout.HORIZONTAL);
        newLayoutParent.setWeightSum(10.0f);

        // get the View returned from ListPreference 
        View listPreferenceDefaultView = super.onCreateView(parent);

        // new layout values for this View
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        params1.weight = 9.0f;

        listPreferenceDefaultView.setLayoutParams(params1);

        //--Button to be added to newLayoutParent --// 

        LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        params2.gravity = Gravity.CENTER_VERTICAL;
        params2.weight = 1.0f;

        Button b = new Button(getContext());
        b.setText("A button");
        b.setLayoutParams(params2);


        // add the two views
        newLayoutParent.addView(listPreferenceDefaultView);
        newLayoutParent.addView(b);
        newLayoutParent.setId(android.R.id.widget_frame);

        return newLayoutParent;
    }
}

So, as you can see in ‘Prefs002.java’, I override onCreateView to make a new Layout for the ListPreference made of a LinearLayout that contains the View that the ListPreference makes itself plus a new Button, that is placed at the right of the View generated by the ListPreference.
Graphically this works, BUT if I click on this new View, the dialog of the Preference is not shown (also when you click it, the row doesn’t change to the yellow color, but I can fix that by adding a TouchListener).
Also, according to the documentation, if I override OnCreateView I should set ‘widget_frame’ to the new View and I did it in the line newLayoutParent.setId(android.R.id.widget_frame);
but that doesn’t make the Dialog to appear when I click this View.

So, How can I call the Dialog of this custom ListPrerence?

Thanks in advance.

  • 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-11T08:53:50+00:00Added an answer on June 11, 2026 at 8:53 am

    You can trigger the dialog by calling showDialog() (DialogPreference.showDialog). When you call super.onCreateView, the view returned will already have one with ID widget_frame.

    I would suggest something like this:

    View v = super.onCreateView(parent);
    View widgetFrame = v.findViewById(android.R.id.widget_frame);
    // add/remove stuff into widgetFrame here
    return v;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my preferences xml file: myPreferences.xml: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory> <EditTextPreference
Consider this preferences.xml file: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android android:title=@string/preference_main> <PreferenceScreen android:title=@string/preference_sight android:key=category_sight> <ListPreference
i have the following xml: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=Ringtone preference android:key=ringtone_option_preference>
I have a simple preferences.xml: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent > <PreferenceCategory
I have the following XML. <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=@string/preference_xxx_category> <CheckBoxPreference android:title=@string/preference_xxx_dual_mode_title
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 the following code in my application in res/xml/preferences.xml: <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=Wi-Fi
I have a simple preference screen defined like this <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=Security> <CheckBoxPreference
i have an option to mute in my menu options like this: <?xml version=1.0
<PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=First Category android:textSize=20px> <CheckBoxPreference android:title=Checkbox Preference android:defaultValue=false android:summary=This preference can be

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.