Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android. Hide certain listview separator

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.

like image 585
Georgy Gobozov Avatar asked Sep 19 '11 20:09

Georgy Gobozov


2 Answers

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).

like image 180
Timur_C Avatar answered Oct 18 '22 11:10

Timur_C


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.

like image 35
slayton Avatar answered Oct 18 '22 11:10

slayton