0

I've implemented SmoothRefreshLayout library in my application, which has at the moment a simple ListView. The problem occurs when I scroll down the ListView and, when I try to get to the top of it, instead of scrolling up, it invokes the Refresh listener. So the movement is stuck.

This is the activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<me.dkzwm.widget.srl.SmoothRefreshLayout

    android:id="@+id/smoothRefreshLayout"
    android:layout_width="match_parent"

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        android:indeterminateDrawable="@drawable/circular_spinner" >
    </ProgressBar>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lv"

        />
</RelativeLayout>
</me.dkzwm.widget.srl.SmoothRefreshLayout>

And this is the part of the RefreshListener in the onCreate:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setTitle("");
        setContentView(R.layout.activity_main);

        refreshLayout = (SmoothRefreshLayout)findViewById(R.id.smoothRefreshLayout);
        refreshLayout.setHeaderView(new MyCustomHeader(this));

        refreshLayout.setEnabled(true);
        refreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {
            @Override
            public void onRefreshBegin(boolean isRefresh) {

                if (isNetworkAvailable(MainActivity2.this)) {
                    isRef = true;
                    new upd().execute();
                } else {
                    Toast.makeText(MainActivity2.this, getResources().getString(R.string.err_conn), Toast.LENGTH_SHORT).show();
                }

            }

        });
masc
  • 243
  • 1
  • 2
  • 12

1 Answers1

0

I know it has no sense to self reply, but it may help someone else. Anyway, the solution has been simple, I have just implemented an onScrollListener and checked if first item was on the top, if not just disable the Refresher.

listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                int rowpos = (listView == null || listView.getChildCount() == 0) ?
                        0 : listView.getChildAt(0).getTop();
                refreshLayout.setEnabled((rowpos >= 0));
            }
        });

Credits: Can't scroll in a ListView in a swipeRefreshLayout

masc
  • 243
  • 1
  • 2
  • 12