Create/Add footer view to listview in android programmatically

How to implement footer text inside bottom of list view in android activity dynamically.

Footer is mostly used to inform the application users that list view ends here or any kind of app developer message which they want to show at the bottom of list view which dose not affect the whole list view. So here is the complete step by step tutorial for Create/Add footer view to listview in android programmatically.

android-project-download-code-button

How to Create/Add footer view to listview in android programmatically.

Code for MainActivity.java file.

 package com.addfooterviewlistview_android_examples.com;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {

 ListView listView;
 String[] listValue = new String[] 
 {
 "ONE",
 "TWO",
 "THREE",
 "FOUR",
 "FIVE",
 "SIX"
 };
 
 List<String> LISTSTRING;
 LayoutInflater layoutinflater;
 @Override
 protected void onCreate(Bundle savedInstanceState) 
 {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 listView = (ListView)findViewById(R.id.listView1);
 
 LISTSTRING = new ArrayList<String>(Arrays.asList(listValue));
 
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_2, android.R.id.text1, LISTSTRING);
 
 layoutinflater = getLayoutInflater();
 
 ViewGroup footer = (ViewGroup)layoutinflater.inflate(R.layout.listview_footer,listView,false);
 
 listView.addFooterView(footer);
 
 listView.setAdapter(adapter); 
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.addfooterviewlistview_android_examples.com.MainActivity" >

 <ListView
 android:id="@+id/listView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true" >
 </ListView>

</RelativeLayout>

Code for listview_footer.xml file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="ListView Footer"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:background="#cbfd01"
 android:padding="14dp" />

</LinearLayout>

Screenshot:

Create/Add footer view to listview in android programmatically

Click here to download Create/Add footer view to listview in android programmatically project with source code.