你可以使用android提供的SwipeRefreshlayout,你需要支持库:android.support.v4.widget.SwipeRefreshLayout
你也可以这样写你的xml布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.expandablelistviewwithpultoreferesh.MainActivity" >
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ExpandableListView
android:id="@+id/lvExp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
在 MainActivity 中,
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
private SwipeRefreshLayout swipeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
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);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
让您的活动实现 OnRefreshListener 并添加未实现的方法,即
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
swipeLayout.setRefreshing(false);
}
}, 5000);
}
实现的来源(教程):
可扩展的列表视图:-
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
滑动刷新布局:-
http://antonioleiva.com/swiperefreshlayout/
注意:如果你想要一个动画 Expandable listView ,请确保你有一个更新的 Android SDK,你可以试试这个库 https://github.com/idunnololz/AnimatedExpandableListView 它只是扩展了 ExpandableListview