Hiding ListView Header / Hiding Single Divider in a List
Asked Answered
S

4

15

I found this Hide footer view in ListView?. As Yoni poited out correctly, you can hide a header in a ListView by wrapping it into a FrameLayout and setVisibility() of the inner View to View.GONE. This works almost perfect for me, BUT: As the FrameLayout still exists, the ListView adds two dividers to the displayed list. It seems like a single divider with a height of two dividers. Is there a way to hide a single divider of a ListView? Maybe it's possible to change the divider's color to the background, that would be fine for me, too. Any complete other ideas? Perfect!

Please help me. I'm not keen on spending two more hours of trial and error.

Thanks a lot!

Skerry answered 7/1, 2011 at 13:18 Comment(1)
you rock . . .your question helped me thanks !Subordinary
T
4

you can change the dividers color like this:

     <ListView 
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:divider="@android:color/transparent"
    android:dividerHeight="2px"/>
Treadwell answered 7/1, 2011 at 19:45 Comment(4)
Yeah, i know that. Thanks so far. But i need to know, how to change the color of a SINGLE divider DYNAMICALLY.Skerry
how about hiding the current dividers and adding an imageview with the 'divider' drawable in it?Treadwell
That would be one solution, i know this can be done that way. But there must be a more easy way to do that...Come on: It's just one damn (line of) pixel. Why is this possibility (hiding list item/footer/hedaer) given to us, when it's not possible to hide them in a way it really invisible?Skerry
That makes me sad. I have custom headers that show up on some cells, and they look bad with dividers above them, but I see no easy way to remove a divider on demand other than going to a custom one and removing it for the last cell.Camara
C
50

Together with hiding or showing your header or footer, use these functions:

setFooterDividersEnabled()
setHeaderDividersEnabled()
Cupping answered 16/8, 2011 at 22:26 Comment(1)
Is it broken in recent versions of android? 4.4.2+? It is not working for me.Pliny
E
8

you can use xml attributes to hide divider for header and footer in ListView

android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
Eteocles answered 12/2, 2015 at 13:37 Comment(0)
T
4

you can change the dividers color like this:

     <ListView 
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:divider="@android:color/transparent"
    android:dividerHeight="2px"/>
Treadwell answered 7/1, 2011 at 19:45 Comment(4)
Yeah, i know that. Thanks so far. But i need to know, how to change the color of a SINGLE divider DYNAMICALLY.Skerry
how about hiding the current dividers and adding an imageview with the 'divider' drawable in it?Treadwell
That would be one solution, i know this can be done that way. But there must be a more easy way to do that...Come on: It's just one damn (line of) pixel. Why is this possibility (hiding list item/footer/hedaer) given to us, when it's not possible to hide them in a way it really invisible?Skerry
That makes me sad. I have custom headers that show up on some cells, and they look bad with dividers above them, but I see no easy way to remove a divider on demand other than going to a custom one and removing it for the last cell.Camara
J
-1

For disable divider:

ListView.setDivider(null);
Jackjackadandy answered 18/11, 2011 at 4:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.