14

i have content i need to display above my listview and below, so much that a scrollview would be great to use if you could use scrollviews and listviews together. Since thats not the best solution, i've been trying to do a couple of things to add footer content to my listview,

here the pic below shows what happens when i add a different type of row as the last row. I can't get my content to fill the width of the row

alt text

I have a couple of buttons that need to go in the footer. I'm using a custom adapter that extends BaseAdapter.

I have also tried using the addFooterView but i'm confused on how to use the addFooterView method if you are implementing your own adapter. Anyone have any simple examples of how to implement addFooterView on a custom adapter

or

is there a way i can get the row at this position (as seen in the picture ) to display better, here is the code i'm using to create this footer row

        View v = getLayoutInflater().inflate(R.layout.item_listview_footer, null);
        LinearLayout ll = (LinearLayout) v.findViewById(R.id.ll);
        return ll;  // return ll as convertView in getView function

edit:

here is the xml for my footer layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="fill_parent" android:background="@drawable/red" android:orientation="vertical" android:id="@+id/ll">
    <Button android:id="@+id/specialInsButton" style="@style/button" android:text="Add Special Instructions" android:layout_width="fill_parent"/>
    <Button android:id="@+id/addToBagButton" style="@style/button" android:text="Add To Bag"/>
    <EditText android:id="@+id/quantity" style="@style/standard" android:text="1"/>
</LinearLayout>

here is the xml for style/button

<style name="button">
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:textSize">17px</item>
        <item name="android:textStyle">bold</item>
        <item name="android:typeface">sans</item>
        <item name="android:gravity">center</item>
        <item name="android:layout_gravity">center</item>

    </style>

standard style

 <style name="standard">
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_width">wrap_content</item>
    </style>
1
  • Fixed from API19
    – k4dima
    Sep 7, 2017 at 10:20

1 Answer 1

52

You can use addFooterView with a custom adapter. Just be sure to make the addFooterView call before the call to listview.setAdapter().

View v = getLayoutInflater().inflate(R.layout.item_listview_footer, null);
listView.addFooterView(v);
listView.setAdapter(adapter);
7
  • that works fine but my footer view is still not showing properly, any ideas why its still only a few pixels wide instead of "fill_parent" wide ? ? ?
    – slim
    Oct 18, 2010 at 18:18
  • I don't see anything that might be causing this. These buttons are supposed to be stacked vertically and take up the whole width of the screen, right? You should use 'sp' instead of 'px' in your textSize property, but that should be unrelated. Could you post @style/standard for the editText?
    – danh32
    Oct 18, 2010 at 19:14
  • you're right, here's the style <style name="standard"> <item name="android:layout_height">wrap_content</item> <item name="android:layout_width">wrap_content</item> </style>
    – slim
    Oct 18, 2010 at 20:28
  • 1
    Nothing seems wrong to me. Have you tried looking at the view using hierarchyViewer? It should help in finding which view is causing the error. developer.android.com/guide/developing/tools/…
    – danh32
    Oct 18, 2010 at 20:50
  • 3
    This turned out to be a necessity for me for footers to appear at all on 4.1.1. They worked fine on 4.4.4 with the same code...
    – adamdport
    Apr 27, 2015 at 15:08

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.