ListView分隔线的显示

项目中需要在listview中添加footview 出现了两个问题 

1.footview点击报错 空指针 好解决 在itemclickListener中判断位置即可 

2.footview本应隐藏消失的 却显示了分隔线 在stackoverflow发现下面这段话 一下发现了解决办法

写道
The ListView implementation in Android never draws dividers between items that are disabled, which if you are just calling the addFooterView(View v) method then by default your footer will be.

Instead you need to call the addFooterView(View v, Object data, boolean isSelectable) method with isSelectable set to true. You can just pass null for the data object if you don't need it.

 当初加footview时就没注意还有一个方法 上面那段话大意是listview从来不会主动的加入分隔线 只当内容可以点击时才会加上

所以在加入footview时设置为不可选即可 可以同时解决上面2个问题

还有一种情况下 如果没有设置adapter的情况加载了footView 此时调用

listView.removeFooterView(footView);

 会报空指针 但实际上listview和footview都不为空 解决方法是

 设置adapter以后再进行removeFooterView的操作 再没有报空的问题

猜你喜欢

转载自wiseideal.iteye.com/blog/1843890