您可以使用它是由機器人提供的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);
}
源(教程)實施: 可擴展的ListView: - http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
SwipeRefreshlayout: - http://antonioleiva.com/swiperefreshlayout/
注:請確保您有一個更新的Android SDK,如果你還想要一個動畫可擴展列表視圖,你可以嘗試這個庫https://github.com/idunnololz/AnimatedExpandableListView,它只是擴展ExpandableListview
@Sachine,我必須做類似於iPho ne我沒有其他選擇,但是我發現了一種通過內極化器來實現這一點的方法。我會盡快更新。 – PKTomar