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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:43:59+00:00 2026-06-17T09:43:59+00:00

I have following files and classes: xml/preferences.xml : <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory

  • 0

I have following files and classes:

xml/preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory android:title="@string/characters_list">
        <Preference
            android:enabled="true"
            android:key="characters_view"
            android:layout="@layout/characters_view"
            android:selectable="false"/>
    </PreferenceCategory>
</PreferenceScreen>

layout/character_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <com.xxx.widget.ExpandableHeightGridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/characters_gridview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:columnWidth="380dip"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"/>

</LinearLayout>

CharacterAdapter class

class CharacterAdapter extends BaseAdapter {
    @Override
    public int getCount() {
        return characters.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HashMap<String, String> character = characters.get(position);

        View view;

        if (convertView == null) { 
            view = inflater.inflate(R.layout.characters_view_item, null);
        } else {
            view = convertView;
        }

        // ... 

        return view;
    }
}

In PreferenceActivity I trying to populate grid view with items:

protected void onCreate(Bundle bundle) {
     super.onCreate(bundle);

     setContentView(R.layout.settings);

     Preference characters = findPreference("characters_view");
     View view = characters.getView(null, null);

     ExpandableHeightGridView grid = (ExpandableHeightGridView) view.findViewById(R.id.characters_gridview);
     grid.setExpanded(true);
     grid.setAdapter(new CharacterAdapter(getCharacters()));
}

But nothing happens, just see empty preference item 🙁

Does anybody knows how to render GridView inside Preference item?

Thank you 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-17T09:44:00+00:00Added an answer on June 17, 2026 at 9:44 am

    Just did it!

    The solution is very simple. Need to add addOnGlobalLayoutListener on getListView().getViewTreeObserver().

    Finally onCreate method in PreferenceActivity will looks like:

    protected void onCreate(Bundle bundle) {
         super.onCreate(bundle);
    
         setContentView(R.layout.settings);
    
         final ListView list = getListView();
         list.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                // make sure it is not called anymore
                list.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    
                View view = list.getChildAt(1);
    
                ExpandableHeightGridView grid = (ExpandableHeightGridView) view.findViewById(R.id.characters_gridview);
                grid.setExpanded(true);
                grid.setAdapter(new CharacterAdapter(getCharacters()));
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the multi module project this is the parent pom. <?xml version=1.0 encoding=UTF-8?>
I have the following in my build.xml: <target name=compile.baz depends=init> <javac destdir=${build.dir}/classes debug=on> <compilerarg
I have the following four classes: DataConsumer, DataProducer, SomeQualifier, a META-INF/beans.xml and a test.
I have some classes that already use DOM4J to read XML files and provide
I have the following classes in my models file class HardwareNode(models.Model): ip_address = models.CharField(max_length=15)
If I have the following files, I get this error (c2593 in VC9). If
I have a project in which i have the following files main.wxs - directory
I have the following js files in my code for EditInPlace... <?php echo $javascript->link('jquery.js');?>
I have the following three files in the same directory: citysim.cpp #include utils.h using
I have following script that executes all the .reg files in the current directory.

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.