NVO
NVO

Reputation: 2713

Android pull to refresh empty progress (no arrow)

I use the SwipeContainer from Google in my app using this code:

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipeContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/policeButton"
    android:layout_marginTop="10dp">

<ListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/listView"
    android:layout_alignParentEnd="true"
    android:layout_below="@+id/policeButton"
    android:layout_marginTop="10dp" />
</android.support.v4.widget.SwipeRefreshLayout>

In my Gradle file (module.app) I added the following code:

compile 'com.android.support:support-v4:23.1.1'

In MainActivity I placed the following code:

private SwipeRefreshLayout swipeContainer;

protected void onCreate(Bundle savedInstanceState) {
swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);

    swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    loadLights();
                }
            }, 2000);
        }
    });
    swipeContainer.setColorSchemeColors(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light,
            android.R.color.holo_orange_light,
            android.R.color.holo_red_light
            );
}

The pull to refresh code works en will update my list. But: When the refresh action is in progress the turning arrow is not showing up. So there is an empty circle which showing up while refreshing and it will be hidden after loadLights() is completed because I added swipeContainer.setRefreshing(false); in there.

Does anybody have an idea how to show up the turning arrow?

Upvotes: 3

Views: 341

Answers (1)

Kapil Rajput
Kapil Rajput

Reputation: 11565

The problem is that setColorSchemeColors() needs color integers as inputs like Color.BLUE, not color resource IDs.

So to show color of arrow Code should be like :

 swipeRefreshLayout.setColorSchemeColors(Color.BLACK,
            Color.BLUE,
            Color.GREEN,
            Color.GRAY

    );

and for setting color resource IDs code should be like :

 swipeRefreshLayout.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
    );

Upvotes: 1

Related Questions