Remove header for a section Android Amazing Listview

两盒软妹~` 提交于 2019-12-13 04:29:53

问题


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>

回答1:


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);
}


来源:https://stackoverflow.com/questions/16330814/remove-header-for-a-section-android-amazing-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!