Overlay update button on top of listview?

510 Views Asked by At

I am making an android application containing a listview which updates every 30 seconds. If there is new data, I want a button to appear where I can update the feed, similar to the facebook app. How can I accomplish this? Is there a way to overlay a button on top of a listview that appears at the top of the screen when not scrolling in the listview?

Here is my listview xml:

<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:paddingLeft="3dp"
        android:paddingRight="3dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/header"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp"
        />

</LinearLayout>

<Button
    android:id="@+id/update_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:text="Button" />

1

There are 1 best solutions below

0
On

Try using the setOnScrollListener and implement the onScrollStateChanged.

setOnScrollListener(new OnScrollListener() {
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        // TODO Auto-generated method stub
        //make your button invisible
        button.setVisible(false);
    }

    public void onScrollStateChanged(AbsListView view, int scrollState) {
        if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
            //make your button visible.
             button.setVisible(true);

        }
    }
});

Overlaying of views can be seen here.