requirements: Depending on a need, you may need to dynamically adjust ListView header and footer, such as the Header used as a display board.
Difficulty:Listview.addheaderview ()method must be in theSetadapter ()before the method is called, otherwise it throws an exception. As to why the exception is thrown, check theListViewsource code can be found. Therefore, in the setHeaderviewand then you want toHeaderviewTo Remove or hide, you need to wrap a large bend:Adaptersave it.-removed fromheaderview-(or replaceHeaderview)-then theAdapterset it up.
Hidden Headerview idea: Using View.gone property to Hide
Try 1.itemView The structure is as follows:
1 <linearlayout android:id= "@+id/item_root"
2 Android:layout_width= "Fill_parent"
3 android:layout_height= "50dip"
4 android:orientation= "Vertical" >
5 <textview android:id= "@+id/tv_1"/>
6 <textview android:id= "@+id/tv_2"/>
7 </linearlayout >
According to the truth, the last sentence should be able to play a hidden headerview item_root There really is no control, but item_root occupied 50dip height Still, That is, the original headerview view.invisibile
continue to try the following to modify The structure of the Itemview:
1 <linearlayout android:id= "@+id/item_root"
2 Android:layout_width= "Fill_parent"
3 android:layout_height= "50dip"
4 android:orientation= "Vertical" >
5 <linearlayout android:id= "@+id/item_container"
6 <textview android:id= "@+id/tv_1"/>
7 <textview android:id= "@+id/tv_2"/>
8 </LinearLayout>
9 </linearlayout >
This structure adds an excess to the previous structure Layout ( Item_container ) to encompass Item internal controls. At this point, if you are item_container setvisibility (view.gone) , you can achieve the purpose of hiding Headerview perfectly !
Conclusion: View.gone property does not seem to work at the root Layout on.
New questions:
if the Item_root on the use of Shape background, and this background exists MinSize , then this method fails again ...
circumvention: If you really have toHeaderviewAdd background onbackground, then pleasebackgroundset inItem_containerGo on, don't set theItem_root, so you can avoid new problems. Recommend a modelAPPBeta Platform-Love Beta (http://www.ineice.com/).
How to implement a ListView that can dynamically adjust hidden headers