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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:27:29+00:00 2026-06-13T11:27:29+00:00

I have an ExpandableListView and am setting a customized BaseExpandableAdapter to it. My question

  • 0

I have an ExpandableListView and am setting a customized BaseExpandableAdapter to it. My question is, Can I inflate the Layout(XML) that I want to be displayed in the constructor of the Adapter itself, rather than inflating it in the getChildView() each time? I will be dynamically changing the images that are to be displayed with each expandable List to be selected in getChildView() though. The code goes here.

public class MyExpandableListAdapter extends BaseExpandableListAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    GridLayout gl = null;
    HorizontalScrollView hScrl;
    public MyExpandableListAdapter (ArrayList<SensorType> parentGroup, Context context) {       
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        View view = infalInflater.inflate(R.layout.expandlist_items, null);
    gl = (GridLayout) view.findViewById(R.id.gl);
        hScrl = (HorizontalScrollView) view.findViewById(R.id.hScroll);
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
       if (childPosition == 0) {
            gl1.removeAllViews();
        }
        int mMax = 8; // show 8 images
       for (int i =0; i < mMax; i++) {
        ImageView myImg = new ImageView(mContext);                            
                myImg.setBackgroundRes(R.drawable.image1);
                gl.addView(myImg);
          }

return hScrl;
}

Is there any problem with above, it is displaying the images correctly and scrolling as well if there are more images. But my question is, this job of inflating layout and getting the gl and hscrl, should this be in the constructor of the Adapter(as shown above) OR should it be in the getChildView???

These 4 LOC:

mInflater = LayoutInflater.from(mContext);
View view = infalInflater.inflate(R.layout.expandlist_items, null);
gl = (GridLayout) view.findViewById(R.id.gl);
hScrl = (HorizontalScrollView) view.findViewById(R.id.hScroll);
  • 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-13T11:27:30+00:00Added an answer on June 13, 2026 at 11:27 am

    I have found out that If I need a layout to be inflated again and again for each item in the adapter then the inflate should be done in getChildView() or getView() of any adapter.
    However in the above code I am inflating it once in the constructor and adding the images manually to a GridLayout hence I need not inflate it again and again in the getChildView().
    Hence it works fine, as it is inflated once in the constructor of the adapter.

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

Sidebar

Related Questions

If i have a expandablelistview with custom layout (group.xml and child.xml), the are any
can we have ExpandableListView inside ListView so that I can have group level first
I can't create layout in which I will have <LinearLayout> <TextView/> <ExpandableListView/> <Button/> </LinearLayout>
I have an ExpandableListView that I want to populate with my custom views of
I have an ExpandableListView with children that have text supplied on creation, and an
I have an custom ExpandableListView Adapter: public class MyExpandableListView extends BaseExpandableListAdapter { private Context
I have ExpandableListView and I extended BaseExpandableListAdapter for my own adapter. I am having
I have an ExpandableListView and an ExpandableListAdapter. When I call notifyDataSetChanged() in my adapter,
If I want to have an ExpandableListView, which gets data from a response from
Here is what I'm working with: I have an ExpandableListView that uses a SimpleCursorTreeAdapter

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.