Reputation: 7
My code below shows what I want to make. I want to insert a view as a footer to a ListView. However It seems that I can only enter an edit text or a button separately, not as one all together view. I know this sounds confusing. Thanks for any help.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:background="@drawable/bg_card"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp" >
<EditText
android:id="@+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:textColor="#000000"
android:textSize="22dp"
android:textStyle="bold" />
<Button
android:id="@+id/newButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</LinearLayout>
Upvotes: 0
Views: 66
Reputation: 3645
Inflate the layout:
View v = LayoutInflator.from(context).inflate(R.layout.footer, null);
And add it as footer to the listview:
listview.addFooterView(v);
Edit: If you are targeting api level < kitkat, you have to call addFooterView before calling
listview.setAdapter();
Upvotes: 3
Reputation: 2377
I'm not aware of any problem with making a LinearLayout be your footer view. Your XML does have some issues, however.
Here is a version with those fixes:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:background="@drawable/bg_card"
android:orientation="horizontal"
android:padding="10dp" >
<EditText
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="22dp"
android:textStyle="bold" />
<Button
android:id="@+id/newButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>
If you are still seeing problems, maybe you can describe what shows up.
Upvotes: 0