Android ListView custom header - android

I have a custom listview, which is re-arrangeable(drag & drop) and obviously scrollable. I need to add a custom header with this listview which should scroll with the list.
I have tried "listView.addHeaderView(header)" with a custom header layout. But header becomes messed up during list re-arrangement. So I don't want to use addHeaderView(...).
I have also tried to put my activity layout which is a LinearLayout, inside a ScrollView and expand the list as suggested here - How can I put a ListView into a ScrollView without it collapsing?. But, scrolling seems slow and ScrollView is creating issue in list item re-arrangement.
So is there any other way to accomplish this effect? I would prefer some solution in layout.
I am fairly inexperienced in Android UI. Thanks in advance.

You can add a Header View to your list, using the following code,
View header = getLayoutInflater().inflate(R.layout.header, null);
ListView listView = getListView();
listView.addHeaderView(header);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice,android.R.id.text1, names));
But for this, you need to define layour for the Header View, check this Link Android ListActivity with a header or footer
Edit- As per comment, I would like to mention that, It is not a good practice to use a ListView inside a ScrollView. The best possible solution, I found so far is to add HeaderView to your ListView. It would be better if the OP could mention, what problems he is facing with the HeaderView
If you want a scrollable header, you should definitely go with the HeaderView. But if you want to have a static header above the ListView, you could use a TextView as a Heading of the ListView.

you can add static header in layout I mean the layout where you have scrollview above that add a linear layout for static header go through this question
it will help you

If you don't want that your list having a horizontal scrollview so you can create a Xml layout with horizontal linear layout(same as your list Layout) then include it at the top of your listview layout but if you want it horizontally srcollable so you have two choice : one is what you mention as addheader view and second is a Custom ScrollView which you can find a good solution here

Related

Disabling the scroll of listview

I have created a listview inside scrollview. Atfirst it was not scrolling but when it started scrolling then layouts below list view started disappearing from screen. is there any solution to dynamically calculated he height of list view and assign it or is it possible that some how the scrolling of listvew is disabled so that only its items appear on screen like normal layouts or any tags and it does not scrolls???
ListView is deprecated. I would suggest you to use RecyclerView and add nestedScrollingEnabled="true" to your xml or call RecyclerView.setNestedScrollEnabled(true) if you want to wrap adapterview with a scroller. You can also try NestedScrollView for support compability.
Good luck

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.

Margin bottom headerview in listview

I'm implementing a listview that looks like this :
So basicly I have a listview, with a headerview. My problem is to set the space between the headerview and the rest of the listview. If anyone has a clue, thanks :)
To set a gap below the header view you can just add marginBottom to the header view. That should do it. But like Pauland said, never ever EVER put a listview inside a scrollview. You are basically placing two vertical-scrolling views ontop of each other and Android can't tell which one to scroll when the user swipes!

scrollView linearlayout and listview

I'm doing an android app, and I just want to have an scrollable layout, but inside of this layout I want to put some textView and 2 listView, and this is my problem, the listView.
I need to include this 2 listview on the layout and this is obligatory need to be scrollable, and I googling and all I found is negative.
how can I put 2 listview on scrollView?? is not possible? and if its right what can i do? Which is the alternative that I have? I really desesperated because I spend all day!!
con someone say me an example of this?
really thanks!
ListViews shouldn't be placed inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all get handled by the parent ScrollView. However you can add views you want to be scrolled to the ListView as headers or footers.

Android List View

In my Layout there are some widgets are there in above to the list view. When i scroll through the list view i want to scroll my layout fully.Please any one can suggest the answer
Put the widgets that are presently above the ListView inside the ListView, either by using addHeaderView(), my MergeAdapter, or your own custom Adapter class. The, those widgets will scroll along with everything else in the ListView.

Categories

Resources