Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwipeRefreshLayout Freezes on API 4.2.2

Everything works fine on my Nexus 5 with API 21 and above, but on an older samsung device with API 4.2.2 I get the following bug with SwipeRefreshLayout.

Anyone experiencing anything similar?

enter image description here

When I pull down to refresh the refresh freezes, until I start scrolling back up.

This is a very off the top of my head hunch, but would it have something to do with something messing up in the new support library updates? I am currently using the following support libraries:

compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:palette-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'

This problem is occurring in several activities for me, but as an example I am instantiating the SwipeRefreshLayout simply like this, there is nothing unusual about it. It is inside a Fragment:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground"
android:orientation="vertical">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeToRefresh"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

I initialize the SwipeRefreshLayout like so:

private void initSwipeRefreshLayout() {
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mSwipeRefreshLayout.setRefreshing(true);
            refreshContent();
        }
    });

    mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light,
            android.R.color.holo_orange_light,
            android.R.color.holo_red_light);
}

private void initRecyclerViewScrollListener() {
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);

            visibleItemCount = mRecyclerView.getChildCount();
            totalItemCount = mLayoutManager.getItemCount();
            firstVisibleItem = mLayoutManager.findFirstCompletelyVisibleItemPosition();
            lastVisibleItem = mLayoutManager.findLastCompletelyVisibleItemPosition();

            int pageMultiplier = page * PER_PAGE;

            if (!loading) {
                if ((pageMultiplier == totalItemCount) && (lastVisibleItem == pageMultiplier - 1)) {
                    loading = true;
                    page += 1;
                    mPresenter.loadMoreStuff(mStuff.getId(), page, PER_PAGE);
                    mSwipeRefreshLayout.setRefreshing(true);
                }
            }
        }
    });
}

EDIT: If this is relevant, these problems all occur inside Fragments

like image 539
AndyRoid Avatar asked Oct 30 '22 17:10

AndyRoid


1 Answers

I believe the problem was occurring due to changes for SwipeRefreshLayout in v23 compared to v22, same for RecyclerView. Everything works fine after switching to v23.0.1

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:palette-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
like image 172
AndyRoid Avatar answered Nov 15 '22 06:11

AndyRoid