Fixed and always visible footer below ListFragment

I am trying to attach a footer, fixed and always visible, at the bottom of the list.

I am currently doing it like this:

@Override public void onActivityCreated(Bundle savedInstanceState) { // ... adapter = new MyAdapter(getActivity(), R.layout.list, dataList); ListView list = getListView(); View footer = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_add, null, false); list.addFooterView(footer); setListAdapter(adapter); } 

While this code creates a view at the bottom of the list, it really does not do what I want:

First, I need a FIXED footer, that is, visible on the screen, regardless of where the list scrolls. With this solution, the footer is only displayed when the screen scrolls to the bottom of the list.

Secondly, I need a footer, even if the list is EMPTY. In this solution, the footer is not displayed when the list is empty.

What is the best way to get a fixed footer (in my case, a button) that always appears under a list or list?

Thank!

+14
android android-listview android-listfragment
Sep 10
source share
1 answer

You can do this in xml layout:

 <RelativeLayout> <Button android:id="@+id/footer" android:layout_alignParentBottom="true"/> <ListView android:id="@android:id/list" android:layout_above="@id/footer"> <!-- the list --> </RelativeLayout> 

This layout will be used in the onCreateView method of the fragment.

+40
Sep 10 '12 at 14:40
source share



All Articles