0

I have a list view.

I want to add footer.

So i create a footer xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="@drawable/background_news_list"
android:gravity="center" >

<ImageButton
    android:id="@+id/btn_more"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10px"
    android:background="@drawable/btn_more_news" />

</LinearLayout>

I want inflate entire layout into main java but i manage to inflate button only

footer = getLayoutInflater().inflate(R.layout.testing, null, false);
btnmore = (ImageButton)footer.findViewById(R.id.btn_more);

ListView lv = (ListView) findViewById(android.R.id.list);
lv.addFooterView(footer);

my list is in this xml

<LinearLayout
    android:id="@+id/layout_content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/layout_menu"
    android:layout_below="@id/layout_title"
    android:orientation="vertical" >

    <ListView
        android:id="@+android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>
</LinearLayout>

How do i create a viewgroup to fulfill and become like this?

footer = getLayoutInflater().inflate(R.layout.testing, parent, false);

So that i can use my own linear layout.

Alan Lai
  • 1,094
  • 7
  • 18
  • 41

2 Answers2

0

Your post is a little confusing but I think you just need to add an id to your LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/linlayoutid"
    android:layout_width="fill_parent"
    android:layout_height="100px"
    android:background="@drawable/background_news_list"
    android:gravity="center" >

<ImageButton
    android:id="@+id/btn_more"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10px"
    android:background="@drawable/btn_more_news" />

</LinearLayout>

Then grab the linear layout:

footer = getLayoutInflater().inflate(R.layout.testing, null, false);
LinearLayout ll = footer.findViewById(R.id.linlayoutid);

ListView lv = (ListView) findViewById(android.R.id.list);
lv.addFooterView(ll);
James Cross
  • 7,799
  • 8
  • 24
  • 30
0

I solved it by doing this

footer = getLayoutInflater().inflate(R.layout.testing, lv, false);

This is because

lv is the list id and it 
Alan Lai
  • 1,094
  • 7
  • 18
  • 41