Add progressbar at bottom of a listview
Asked Answered
U

2

6

I'm creating a simple listview with an endless scroll effect. While I'm downloading new data I want to display an indeterminate progressbar at the bottom of the listview (like gmail app).

There is 2 solutions

  • Add the progressbar as a an item of my listview, but I don't like this solution
  • Add the progressbar at the bottom of my listview and show/hide it

It would give something like that

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

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

    <ProgressBar
        android:id="@+id/trobber"
        android:layout_below="@+id/List_list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true" >
    </ProgressBar>

</RelativeLayout>

But the progressbar is not displayed when my list is longuer than the size of my screen (in other words when I have to scoll).

Undulation answered 13/6, 2013 at 20:34 Comment(0)
U
7

use instead yourListView.addFooterView(put your ProgressBar View)

Unbending answered 13/6, 2013 at 21:32 Comment(4)
Thank you, you saved me a lot of time !Undulation
After adding FooterView to my listview I am getting class cast exception when I try to set an adapter to the listView??Spunk
hello you got solution for this..??Nummary
@Spunk This is a problem in older versions of android e.g. JellyBean.Viewless
C
2

To be elaborated, here's how you do it:

A. Create a layout xml file, name it as progress_bar_footer.xml

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

    <ProgressBar
        android:layout_width="30dip"
        android:layout_height="30dip"
        android:layout_gravity="center"
        android:indeterminateTint="@android:color/holo_green_light"
        android:id="@+id/progressBar5"/>

</LinearLayout>

B. In your activity,

View mProgressBarFooter = ((LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.progress_bar_footer, null, false);

C. Use it.

listView.addFooterView(mProgressBarFooter); //or
listView.removeFooterView(mProgressBarFooter);

Credit goes to this John Moses' page.

Counterclockwise answered 26/9, 2016 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.