简体   繁体   English

Android:删除listview中某些列表项的分隔符

[英]Android: remove divider of some listitems in listview

I've created a listview with a BaseAdapter . 我用BaseAdapter创建了一个listview。 I want some of the listitems to have a divider, but from some of the listitems, I want to remove the divider. 我想要一些listitems有一个分隔符,但是从一些listitems,我想删除分隔符。 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? 我知道你可以通过设置.setDivider(null).setDividerHeight(0)来删除整个列表的分隔符,但是也可以从列表中的单个列表项中删除分隔符吗?

Thanks in advance! 提前致谢!

您可以为整个列表禁用分隔符,并为每个ListItem设置自定义视图,例如设置具有或不具有底部边框的不同背景绘制。

Yes you can remove divider from specific list items using the `getView` method in your adapter (which extends the baseadapter) 是的,您可以使用适配器中的`getView`方法从特定列表项中删除分隔符(扩展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: ofc你的适配器中有类似data东西,这些数据是指显示在listview中的数据,所以在你的getview方法中检查这样的特定项:

if(data[position].ID == YourElemetnsID)
inflate with the specific list item layout
else
inflate with the general list item layout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM