Spinner does not animate when pulling down a list

356 views Asked by At

I have a listview and the user should see an animated spinner when he is pulling down the list.

I use a SwipeRefreshLayout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipeLayoutEvents"
    android:orientation="vertical">

    <ListView
        android:id="@+id/eventlist"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView
        android:id="@+id/emptytext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Keine anstehenden Veranstaltungen"
        android:textColor="#555555"
        android:textSize="20sp" />
</android.support.v4.widget.SwipeRefreshLayout>

onCreateView in my Fragment:

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.event_fragment_layout, container, false);
    [...]
    swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeLayoutEvents);
    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light,
            android.R.color.holo_orange_light,
            android.R.color.holo_red_light);
    return view;
}

onRefresh:

@Override
public void onRefresh() {
    swipeLayout.setRefreshing(true);

    DataHolder dh = new DataHolder();
    dh.receiveData();
    allEvents = dh.getEvents();
    eventAdapter.setEvents(events);
    eventAdapter.notifyDataSetChanged();

    swipeLayout.setRefreshing(false);
}

I get a spinner, but it is not animated. When I delete swipeLayout.setRefreshing(false);, the spinner animates when the method is over.

What am I doing wrong?

UPDATE:

public void receiveData(){
    try {
        events = new XmlService().execute().get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}

The XmlService is an AsyncTask.

0

There are 0 answers