简体   繁体   中英

Remove header for a section Android Amazing Listview

In my ListView (using library Android Amazing Listview), I have 2 sections and I want to hide the header of 1st section. I tried with

view.findViewById(R.id.header).setVisibility(View.GONE);

in the bindSectionHeader() but it doesn't hide the header, instead it would just make it move over my row.

So, is there way to hide the section header for the 1st section? All I need is to show the header of section 2 (to make it visible at all times). Any help is greatly appreciated.

The ListView item XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/product_section_header"
        android:background="@android:color/white" />

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/screen11_low_opacity"
        android:gravity="center"
        android:text="TextView"
        android:textColor="@android:color/black"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/iv_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/stub" />

</LinearLayout>

The header XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:src="@drawable/screen11_flag" />
</LinearLayout>

After playing around with the Android Amazing Listview , I was able to mould it to satisfy my requirements. So here is what I did...

In configurePinnedHeader() , hide the overlay header:

if(getSectionForPosition(position)==0){    //hide header
    lSectionHeader.setText("");
    lSectionHeader.setBackgroundColor(Color.TRANSPARENT);
}
//in else block, you have to set the background (when you are setting the text)

In bindSectionHeader() , hide the header which we added in the cell:

if(getSectionForPosition(position)==0){
    TextView lSectionTitle = (TextView) view.findViewById(R.id.header);
    lSectionTitle.findViewById(R.id.header).setVisibility(View.GONE);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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