Reputation: 21076
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 reference to it, and when I want the user to see it, I set the visibility to View.VISIBLE.
For the most part, this works great. However, the footer seems to still take up space. If the user uses the scroll wheel/pad, the area the footer is taking up gets highlighted. I'd like to polish this more so the footer is completely gone; ideally without detaching it from the ListView.
Is this possible? Or am I going to have to set/unset the foot instead of simply toggling its visibility?
Upvotes: 5
Views: 8682
Reputation: 61
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"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LogoLinearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android: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>
Upvotes: 2
Reputation: 621
Set isSelectable parameter to false when You call addFooterView to disable footer selection and highlighting
Upvotes: -1
Reputation: 30168
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:
onCreate
addFooterView()
THEN initialize your adapter (keep an instance reference to it) and call setAdapter()
. This will leave the ListView
"prepped"notifyDatasetChanged()
removeFooterView()
(it will hide it if it's being displayed and do nothing otherwise)addFooterView()
if the footer needs to be displayed Upvotes: 10
Reputation: 19250
Try using View.INVISIBLE instead of View.GONE. (I have not tried this,but it might work)
Upvotes: -2