標籤:
問題:
I have a ListView that‘s using a custom adapter. I want to dynamically add/remove items from the ListView. I‘ve tried everything inside the getView() method in my view adapter. I‘ve tried doing setVisiblity(View.GONE) on the view I‘m returning. And it in fact doesn‘t draw the view, but it still allocates space for the view and it‘s just a blank black space.
Is this even possible to set items in ListView invisible?
回複:
You need to call setVisiblity(View.GONE) on the returned view and all the views inside it. If you are reusing the convert view passed in you need to remember to call setVisiblity(View.VISIBLE) on all the views you want visible.
If you have a lot of invisible views you may need to set the divider height to 0 and add your own divider to the returned views. Otherwise the ‘invisible‘ views will each have a visible divider and produce a noticeable gray line between visible views.
結論:
1) 將View控制項設定成不可視。
2) 將View內部的控制項設定不可視。
3) 在xml布局檔案將ListView分隔條高度置為0,採用自訂的分隔條。
4) 將View內部的分隔條設定不可視。
5) 第一行分隔條不可視。
Making a view in a listview invisible android