我有一个列表视图,用户在下拉列表时应该会看到一个动画微调器。
我使用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:
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);
}
我得到一个微调器,但它没有动画。当我删除swipeLayout.setRefreshing(false);
时,微调器在方法结束时动画。
我做错了什么?
更新:
public void receiveData(){
try {
events = new XmlService().execute().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
XmlService是一个AsyncTask。