Android. Hide certain listview separator
Asked Answered
V

2

17

How I can hide or delete certain listview separator? Of course I can hide all dividers

getListView().setDivider( null ); 
getListView().setDividerHeight(0); 

but I need hide one or two dividers in my listview. for example by position. I am using custom Adapter for list data. Thanks.

Velma answered 19/9, 2011 at 20:29 Comment(0)
M
7

You can either create a custom View for each ListItem where you can turn on or turn off the separator, or you can create a separator view that you add into your list view at the proper locations.

Marthmartha answered 19/9, 2011 at 20:41 Comment(6)
I have a custom layout for list item. But I dont know how to add or remove divider on each item. I suppose than divider is common thing for all listview.Velma
so simply add a seperator looking view to the top or bottom of the layout and set it visible or invisibleMarthmartha
slayton, sorry but dont undestand you. You talks that I can add a divider in my list item, but this divider what it is? TextView, ImageView etc? In listview prpoperties there is divider property - common for all list. How I can set up this property for every item? Maybe you mean disable "native" dividers as mentioned in my code above and emulate divider as additional view in my list item view? Right?Velma
@Georgy gobozov. " Maybe you mean disable "native" dividers as mentioned in my code above and emulate divider as additional view in my list item view? Right? " yes thisMarthmartha
I never thought such a simple solution... (manual custom divider) Thanks for thinking for me!Casandracasanova
How to deal with clickable items? If separator is part of item then on click selected area will contain separator too that looks ugly.Vedette
A
16

You can hide horizontal divider for disabled items of your list view (commonly used as section headers). To do this return false in areAllItemsEnabled BaseAdapter callback. Again, this only works for those views that are disabled (you return false in isEnabled callback for this item). The documentation for this callback is a little vague:

Indicates whether all the items in this adapter are enabled. If the value returned by this method changes over time, there is no guarantee it will take effect. If true, it means all items are selectable and clickable (there is no separator.)

Reference.

Note that it mentions separator. I'm not sure if this is intended behavior or some kind of side effect. But it works. You can see this in ApiDemos List demo 5 (Separators).

Amateurism answered 1/7, 2013 at 18:52 Comment(1)
Thanks this answer saves my day.Overriding BaseAdapter areAllItemsEnabled and returning false did the tirckFiske
M
7

You can either create a custom View for each ListItem where you can turn on or turn off the separator, or you can create a separator view that you add into your list view at the proper locations.

Marthmartha answered 19/9, 2011 at 20:41 Comment(6)
I have a custom layout for list item. But I dont know how to add or remove divider on each item. I suppose than divider is common thing for all listview.Velma
so simply add a seperator looking view to the top or bottom of the layout and set it visible or invisibleMarthmartha
slayton, sorry but dont undestand you. You talks that I can add a divider in my list item, but this divider what it is? TextView, ImageView etc? In listview prpoperties there is divider property - common for all list. How I can set up this property for every item? Maybe you mean disable "native" dividers as mentioned in my code above and emulate divider as additional view in my list item view? Right?Velma
@Georgy gobozov. " Maybe you mean disable "native" dividers as mentioned in my code above and emulate divider as additional view in my list item view? Right? " yes thisMarthmartha
I never thought such a simple solution... (manual custom divider) Thanks for thinking for me!Casandracasanova
How to deal with clickable items? If separator is part of item then on click selected area will contain separator too that looks ugly.Vedette

© 2022 - 2024 — McMap. All rights reserved.