Scrollable parent with ListView child - android

I know it's considered taboo to place a ListView inside a scrolling container, so is there any "proper" way to accomplish scrolling of a container that has a ListView child in it? An example layout would look something like:
Header
---
"Sub" header
---
ListView with list items
---
Footer
Header and Footer need to remain static on the screen, and the middle content (Subheader and ListView) should scroll between them. I can't have just the ListView scrollable, because the subheader takes up too much space. As it is currently, the Header comes from an <include />, the Subheader contains several views including an Image and some text, and the ListView (actually part of a ViewFlipper) would contain an indeterminate number of items. The Footer has a couple buttons/tabs that are used to control the ViewFlipper (only one of the views in the flipper is a ListView).
The only way I can think of to accomplish this efficiently would be to place the Subheader inside the ListView as the first item -- is there any better way?

I know it's considered taboo to place
a ListView inside a scrolling
container
It's not "taboo", it just will never work.
The only way I can think of to
accomplish this efficiently would be
to place the Subheader inside the
ListView as the first item -- is there
any better way?
You could use addHeader() on ListView to set up your "Subheader" as a ListView header.

Related

Scrolling entire layout with a ListView and another View

I know that is not a good practice put a ListView inside a ScrollView, that's why I want to figure out what kind of solution can handle this.
Look at the image below:
There's a block with some stuff on the top and there's a ListView below, and all of this scrolls with the entire layout. So, the question is:
How do I achieve this?
You should have just a ListView and set a headerView to this ListView to achieve what you want.
Use header View:
ListView below scrollview in Android
or Sticky List Headers if you want to make them stick on top of the listview:
https://github.com/emilsjolander/StickyListHeaders
or use different ViewTypes with your own Adapter implementation:
Listview: Only one list item with multiple textviews
Why do you assume the reviews shown there are in a ListView? To me they just look like a handful of custom Views stacked on top of each other, not an actual ListView.

How to implement Custom ScrollView Like listview?

I want to add my Listview in another scroll view but when i add it in scrollview in xml it show only one item.so i want to create custom scroll view so i can put it in another scrollview.
Things to take into account:
ScrollView can only have a single child. If you want to add more of them you have to put them inside another ViewGroup, then add it to the ScrollView.
ListView handles its own scrolling, you should never put it inside another ScrollView.
If what you need is to have a certain number elements, a list of items included, scroll together as a single entity, you have two options:
Do not use a ListView, but a vertical LinearLayout. It will work, but with this all your rows will be created at once and won't be recycled while scrolling, so you should only do this if you can be sure your list will have a limited number of items.
A better option is to use a ListView as your main ViewGroup and add to it every other element you need in the scroll as headers or footers.

Linear layout with nested listview scrolling

I have a LinearLayout with a nested listview which looks like this:
<LinearLayout ... >
<LinearLayout>
</LinearLayout>
<ListView>
</ListView>
</LinearLayout>
The problem is that the listview owns the scrollbar (so only content in the listview is scrollable) but i actually want the parent LinearLayout to own the scrollbar (so making the entire content scrollable).
Wrapping parent ListView in a ScrollView hasn't been successful because the ScrollView doesn't recognize ListView height (which looks like is rendered at running time)
Thanks
Edit: SOLVED My perfect solution was using a MergeAdapter, as advised by Barak
You can use CommonWares MergeAdapter which allows you to define views and list adapters, pour them into the MergeAdapter and get a single list adapter out, containing everything you poured in, and it scrolls as one list.
A previous answer about MergeAdapter I gave with some instructions is here
You could replace the Listview with a Tableview instead, as long as the listview does not have too many items in it. You can still use a childview with the tableview in much the same way as the listview, you just won't be able to databind it in the same way as you can with a listview, and the items won't recycle either.
Since the listview is designed to contain more items than can be displayed the height will never exceed the screen size (best case) which is the intent of the control, though I suppose you could force it to be larger that seems generally like a bad idea for a lot of reasons.
I suspect what you should do is either create a custom listview adapter, and based on position in the list create the view you want, this would allow all items to scroll like you want.
Listview with different view types per row
This may or may not work depending on what exactly you are trying to do, otherwise you might just want to add views to a linear view inside a scroll view san's the listview.
It just depends on the use case (how many items in the list view, memory issues etc) and what the purpose of the other views are.

Merging ViewFlipper with ListView

What I'm trying to do is to have horizontal ViewFlipper and Listview, both with custom ArrayAdapters, inside LinearLayout which would be vertically scrollable on whole screen.
1) Tried adding ViewFlipper as a ListView header but then I can't use GestureListener since ArrayAdapter takes control over it like it's ListView item.
2) Tried putting them together inside LinearLayout but ViewFlipper's position is fixed and ListView is scrollable inside rest of the screen.
3) Trying with MergeAdapter but it can't handle swipe gesture on it's first element (ViewFlipper), it always returns ViewFlipper's item position.
Here's the picture to clarify what I'm trying to make. Top Stories is ViewFlipper and Latest Posts is ListView. And they both scroll vertically. Ignore bottom tabs and ActionBar as they are static (nonscrollable).
You've got your work cut out for you.
Here are two approaches:
1) Set the view flipper as the first row in the List view. Its a special case. Not as a header, but as a regular row.
2) Use a scroll view, and do not use the list view at all. You may have performance problems if your data for the list view is a large number of items.
Take a look at the ViewPager from the Android Compatibility Library it does what you need

Is it possible & efficient to put a LinearView and ExpandableListView inside a ScrollView

I'm making a GUI with two different parts. The first part (at the top) is composed of some banners, several fixed buttons. So I think using LinearLayout is the most straightforward way to implement. The second part is composed of several similar items grouped together which can be implemented by using ExpandableListView, I think.
However the problem is that the content exceeds the screen size. So I intend to put two of them into a ScrollView. I checked several sources, it seems that putting "ExpandableListView" inside a ScroolView is NOT possible, or not efficent, so I'm afraid...
Would you help to confirm if this is possible? efficient ?
If no, would you give me some recommendations for this layout design?
I'm indeed looking forward to your supports.
Sincerely.
If you have a fixed header at the top of a list, use ListView's header view feature.
Putting ListViews in ScrollViews fundamentally makes no sense and here is why:
ListView has one purpose: to efficiently display unbounded data sets. Since these can be extremely large (tens of thousands of items and more) you do not want to create a View for each item up front. Instead, ListView asks its Adapter for Views only for the items that currently fit in the ListView's measured space on screen. When an item's View is scrolled out of sight, ListView disconnects that View and hands it back to the adapter to fill out with new data and reuse to show other items. (This is the convertView parameter to an Adapter's getView method.)
ScrollView also has one purpose: to take a single child view and give it "infinite" vertical space to fit within. The user can then scroll up and down to see the full content.
Now given this, how many item Views would a ListView create for a 100,000 item Adapter if it had infinite height available to fill? :)
By putting a ListView inside a ScrollView you defeat ListView's key purpose. The parent ScrollView will give the ListView effectively infinite height to work with, but ListView wants to have a bounded height so that it can provide a limited window into a large data set.
Well Expandable List View itself has scrollable property by placing it in scroll view is really undesirable.As the both scroll would contradict and smooth scrolling can't be obtained in that case..
If we have any data to be shown prior or later to list...
Best way is to use header and footer view to list...
I recommend you use header and footer in your case.

Categories

Resources