Skip to content Skip to sidebar Skip to footer

Hiding Footer In Listview

When my Activity loads, I inflate a layout file that I use for a footer. I attach it to the ListView (addFooterView) and then set its visibility to View.GONE. I maintain a refere

Solution 1:

You can use listView.removeFooterView(view). The easiest way to do this is to create an instance variable to hold your inflated footer view (so you only inflate it in onCreate() ). Then just call listView.addFooterView(instanceFooter) and listView.removeFooterView(instanceFooter) as needed.

Edit: Here's what I'm doing to get this to work:

  1. inflate footer layout(s) in onCreate
  2. onResume: IF the adapter has not been instantiated, call addFooterView() THEN initialize your adapter (keep an instance reference to it) and call setAdapter(). This will leave the ListView "prepped"
  3. onResume: update the adapter with the data (I have my data in a separate class) and call notifyDatasetChanged()
  4. Call removeFooterView() (it will hide it if it's being displayed and do nothing otherwise)
  5. Call addFooterView() if the footer needs to be displayed

Solution 2:

You can toggle the visibility. To do that, you need to wrap the content of your footer using a linearlayout, then you set the linearlayout visibility to GONE.

In the example bellow I set the visibility of LogoLinearLayout to GONE and it worked.

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:id="@+id/LogoLinearLayout"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="wrap_content"><ImageViewandroid:id="@+id/Logo"android:src="@drawable/Logo"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="@dimen/spacing3"android:layout_marginBottom="@dimen/spacing3"android:layout_gravity="center" /></LinearLayout></LinearLayout>

Solution 3:

Set isSelectable parameter to false when You call addFooterView to disable footer selection and highlighting

Solution 4:

Try using View.INVISIBLE instead of View.GONE. (I have not tried this,but it might work)

Post a Comment for "Hiding Footer In Listview"