Android: remove divider of some listitems in listview
Asked Answered
B

2

6

I've created a listview with a BaseAdapter. I want some of the listitems to have a divider, but from some of the listitems, I want to remove the divider. I know you can remove the divider of the whole list by setting .setDivider(null) and .setDividerHeight(0), but is it also possible to remove the divider from a single listitem inside a list?

Thanks in advance!

Broken answered 20/3, 2013 at 19:39 Comment(0)
B
5

You could disable the divider for the whole list and set a custom View for each ListItem, e.g. setting different background drawables with or without a bottom border.

Bhatt answered 20/3, 2013 at 20:19 Comment(2)
Seems like a lot of overhead, but I'm afraid that's the only way to go :(Broken
How to deal with clickable items? If separator is part of list item then on click selected area will contain separator too that looks ugly.Charissacharisse
A
2

Yes you can remove divider from specific list items using the `getView` method in your adapter (which extends the baseadapter)

ofc you have something like data in your adapter which refers to the data been displayed into the listview, so in your getview method check for the specific items like this:

if(data[position].ID == YourElemetnsID)
inflate with the specific list item layout
else
inflate with the general list item layout
Aerie answered 20/3, 2013 at 20:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.