How to implement a ListView that can dynamically adjust hidden headers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.