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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:10:46+00:00 2026-05-27T18:10:46+00:00

I have a custom configuration page in my app which just so happens to

  • 0

I have a custom configuration page in my app which just so happens to contain a ListView which you can select/deselect, edit, add to and remove items from. Since the amount of configuration is so large I’ve had to put it all in a ScrollView

My problem is of course that you cannot have scroll functionality within a view which already has it’s own scroll functionality. This means I can’t have a scrolling ListView inside a ScrollView.

What I’ve been trying to do is find the best way of limiting the damage this does. I’ve seen suggestions that say “You could just create a LinearLayout which grows as you add more children”. That would work find by the added effort required to plug in the selectable nature, the reordering & sorting of the list as well as the editing would be a maintanance nightmare.

I’ve spent the day trying to find a way of measuring the height of each ListView item. Once I can find the size of each item (not just the content but any padding and space between items) on each device I know I can simply change the height of the ListView per item added.

Unfortunately I can’t seem to find a way to reliably pull back the height of a listviews child.

(The old chestnut of using a GlobalLayoutListener doesn’t help me pull back the padding between items)

final TextView listLabel = (TextView) toReturn.findViewById(R.id.listLabel);
final ViewTreeObserver vto = listLabel.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

    @Override
    public void onGlobalLayout() {
        listLabel.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        mListItemHeight = listLabel.getHeight();
    }
});
  • 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-27T18:10:47+00:00Added an answer on May 27, 2026 at 6:10 pm

    EDIT

    Expanding ListView’s are you’re friend – This LinearLayout expands based on it’s content. It allows Dynamic ListView‘s inside of ScrollView.

    public class LinearListView extends LinearLayout {
    
        private BaseAdapter mAdapter;
        private Observer mObserver;
        private OnItemClickListener mOnItemClickListener;
        private OnItemLongClickListener mOnItemLongClickListener;
    
        public LinearListView(Context context) {
            super(context);
            init();
        }
    
        public LinearListView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public LinearListView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            init();
        }
    
        private void init() {
            mObserver = new Observer();
        }
    
        public void setAdapter(BaseAdapter adapter) {
            if (this.mAdapter != null)
                this.mAdapter.unregisterDataSetObserver(mObserver);
    
            this.mAdapter = adapter;
            adapter.registerDataSetObserver(mObserver);
            mObserver.onChanged();
        }
    
        public void setOnItemClickListener(OnItemClickListener listener) {
            mOnItemClickListener = listener;
        }
    
        public void setOnItemLongClickListener(OnItemLongClickListener listener) {
            mOnItemLongClickListener = listener;
        }
    
        private int mListSelector = R.drawable.selector_list;
        public void setListSelector(int resid) {
            mListSelector = resid;
        }
    
        private class Observer extends DataSetObserver {
            public Observer(){}
    
            @Override
            public void onChanged() {
                List<View> oldViews = new ArrayList<View>(getChildCount());
    
                for (int i = 0; i < getChildCount(); i++)
                    oldViews.add(getChildAt(i));
    
                Iterator<View> iter = oldViews.iterator();
    
                removeAllViews();
    
                for (int i = 0; i < mAdapter.getCount(); i++) {
                    final int index = i;
                    View convertView = iter.hasNext() ? iter.next() : null;
                    View toAdd = mAdapter.getView(i, convertView, LinearListView.this);
                    toAdd.setBackgroundResource(mListSelector);
                    toAdd.setOnClickListener(new OnClickListener() {
    
                        @Override
                        public void onClick(View v) {
                            if(mOnItemClickListener != null) {
                                mOnItemClickListener.onItemClick(null, v, index, index);
                            }
                        }
                    });
                    toAdd.setOnLongClickListener(new OnLongClickListener() {
    
                        @Override
                        public boolean onLongClick(View v) {
                            if(mOnItemLongClickListener != null) {
                                mOnItemLongClickListener.onItemLongClick(null, v, index, index);
                            }
                            return true;
                        }                   
                    });
                    LinearListView.this.addView(toAdd, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                }
                super.onChanged();
            }
    
            @Override
            public void onInvalidated() {
                removeAllViews();
                super.onInvalidated();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom configuration file in my asp.net website, named urls.config , which
I have custom classes that I currently instantiate within App.xaml as resources. I want
i have custom cell with 2 buttons(the function of these buttons is just to
I have custom component that I can place in my layout file (XML) for
I have a custom-authentication-provider defined in my Spring Security configuration. This class implements AuthenticationProvider,
We have a custom master page that is deployed to My Site, as well
I have a custom PHP framework and am discovering the joys of storing configuration
What is this page for? I have an entry in the configuration file... do
I have a Spring MVC web app which uses FreeMarker for rendering the views
I have a custom control where I loop thru an configuration object to build

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.