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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:13:59+00:00 2026-05-21T11:13:59+00:00

I want to put an gridview with images inside an expandable list…I’ve already make

  • 0

I want to put an gridview with images inside an expandable list…I’ve already make that, but the gridview don’t show all item…

How can i make my expandable list child adapt to the gridview size?

LIST ADAPTER

public class CustomListAdapter extends BaseExpandableListAdapter
{
    String[]            catg    = { "Administração, Escritorio e Industria", "Cultura e Entretenimento", "Educação e Crianças", "Eventos e Estado do tempo", "Amigos, Familia e Habitações", "Multimédia", "Diversos", "Números e Letras", "Restaurantes e Hoteis", "Desporto, Saude e Beleza", "Lojas", "Turismo e Natureza", "Transportes" };

    Context             myctx;


    @Override
    public Object getChild(int groupPosition, int childPosition)
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition)
    {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
    {
        ViewGroup item = getViewGroupChild(convertView, parent);
        GridView label = (GridView) item.findViewById(ipvc.estg.placebook.R.id.gridview);
        label.setAdapter(new GridAdapter(parent.getContext(), groupPosition+1));
        return item;
    }

    private ViewGroup getViewGroupChild(View convertView, ViewGroup parent)
    {
        // The parent will be our ListView from the ListActivity
        if (convertView instanceof ViewGroup)
        {
            return (ViewGroup) convertView;
        }
        Context context = parent.getContext();
        LayoutInflater inflater = LayoutInflater.from(context);
        ViewGroup item = (ViewGroup) inflater.inflate(ipvc.estg.placebook.R.layout.expandable_list_row, null);
        return item;
    }

    @Override
    public int getChildrenCount(int groupPosition)
    {
        return 1;
    }

    @Override
    public Object getGroup(int groupPosition)
    {
        return catg[groupPosition];
    }

    @Override
    public int getGroupCount()
    {
        return catg.length;
    }

    @Override
    public long getGroupId(int groupPosition)
    {
        return groupPosition;
    }



    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
    {
        View item = getViewGroupGroup(convertView, parent);

        TextView text = (TextView) item.findViewById(android.R.id.text1);
        text.setText(catg[groupPosition]);
        return item;
    }

    private View getViewGroupGroup(View convertView, ViewGroup parent)
    {
        // The parent will be our ListView from the ListActivity
        if (convertView instanceof View)
        {
            return (View) convertView;
        }
        Context context = parent.getContext();
        LayoutInflater inflater = LayoutInflater.from(context);
        View item1 = (View) inflater.inflate(android.R.layout.simple_expandable_list_item_1, null);

        return item1;
    }

    @Override
    public boolean hasStableIds()
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition)
    {
        // TODO Auto-generated method stub
        return true;
    }

}

LIST ROW LAYOUT

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <GridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:columnWidth="50dp"
        android:numColumns="auto_fit"
        android:verticalSpacing="10dp"
        android:horizontalSpacing="10dp"
        android:stretchMode="columnWidth"
        android:gravity="center" />
</LinearLayout>
  • 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-21T11:14:00+00:00Added an answer on May 21, 2026 at 11:14 am

    I’ve done tons of searches my own for solving this situation, but didn’t find anything so far, so i’ve made a workaround.

    This workaround assumes that you know / can retrieve the width of your columns, and the height of your grid cell renderers (the dp size set in your layout xmls).

    You should insert a few more lines inside your ExpandableListAdapter‘s getChildView method:

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
    {
        ViewGroup item = getViewGroupChild(convertView, parent);
        GridView label = (GridView) item.findViewById(ipvc.estg.placebook.R.id.gridview);
        label.setAdapter(new GridAdapter(parent.getContext(), groupPosition+1));
    
        // initialize the following variables (i've done it based on your layout
        // note: rowHeightDp is based on my grid_cell.xml, that is the height i've
        //    assigned to the items in the grid.
        final int spacingDp = 10;
        final int colWidthDp = 50;
        final int rowHeightDp = 20;
    
        // convert the dp values to pixels
        final float COL_WIDTH = getBaseContext().getResources().getDisplayMetrics().density * colWidthDp;
        final float ROW_HEIGHT = getBaseContext().getResources().getDisplayMetrics().density * rowHeightDp;
        final float SPACING = getBaseContext().getResources().getDisplayMetrics().density * spacingDp;
    
        // calculate the column and row counts based on your display
        final int colCount = (int)Math.floor((parentView.getWidth() - (2 * SPACING)) / (COL_WIDTH + SPACING));
        final int rowCount = (int)Math.ceil((intValues.size() + 0d) / colCount);
    
        // calculate the height for the current grid
        final int GRID_HEIGHT = Math.round(rowCount * (ROW_HEIGHT + SPACING));
    
        // set the height of the current grid
        label.getLayoutParams().height = GRID_HEIGHT;
    
        return item;
    }
    

    With the addition above i was able to produce the following displayed layouts:

    expandable list with grid - portrait

    and

    expandable list with grid - landscape

    I hope it can help you as well.

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

Sidebar

Related Questions

how to put value in Label inside gridview during runtime? I want to put
I put a hyperlinkfield into a gridview, but I realise sometimes I want it
I want to make a GridView that contains randomly colored squares, and I want
I want to put some images in an area at the application start. As
I have a button inside my <ItemTemplate> in GridView and I want to call
I want to create a gridview form a class and send that gridview as
I have a gridview.Datasource = someDatatable I want to show 5 out of 10
I have a simple Gridview with AutogenerateDeleteButton . I want to put a an
I have a Gridview with a column named Date, i want to put 2
I want to execute the following query and put it on a gridview in

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.