2015-01-08 39 views
1

其實我必須應用兩個功能第一個是拉動刷新視圖,第二個是列表視圖中的動畫可擴展子。需要具有可擴展列表視圖的PullToRefershListView功能

當我點擊一個列表項的按鈕,然後佈局從上到下,當我點擊這個按鈕時,這個佈局再次從下到上。我可以在ExpanableCells項目中看到這個功能。

我還需要當用戶滾動列表視圖,然後我的列表將刷新。

對於這兩個功能我有兩個項目PullToRefreshView庫和ExpandableCells項目,但兩個開發人員以不同的方式應用ListView,我無法使用它們兩個。我只能用它們。

任何人都適用他們請幫助我。或者我必須從基地實施他們兩個。

回答

0

您可以使用它是由機器人提供的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

+0

@Sachine,我必須做類似於iPho ne我沒有其他選擇,但是我發現了一種通過內極化器來實現這一點的方法。我會盡快更新。 – PKTomar