• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    How to add a footer in ListView in android


    Create a footer view layout consisting of text that you want to set as footer and then try

    View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
    ListView.addFooterView(footerView);

    or may be use this also:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="7dip"
    android:paddingBottom="7dip"
    android:orientation="horizontal"
    android:gravity="center">

    <LinearLayout
    android:id="@+id/footer_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center"
    android:layout_gravity="center">

    <TextView
    android:text="@string/footer_text_1"
    android:id="@+id/footer_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="14dip"
    android:textStyle="bold"
    android:layout_marginRight="5dip" />
    </LinearLayout>
    </LinearLayout>

    and on activity
    public class MyListActivty extends ListActivity {
    private Context context = null;
    private ListView list = null;

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    list
    = (ListView)findViewById(android.R.id.list);

    //code to set adapter to populate list
    View footerView = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
    list
    .addFooterView(footerView);
    }
    }


    Happy Coding!!!


    Contact Form

    Name

    Email *

    Message *