2017-12-10 20 views
0

ListViewを含む私のフラグメントの1つにSwipeRefreshLayoutを使用しています。Android Studioでリフレッシュスワイパーハンドラーを設定する

swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh); 

    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 


     @Override 
     public void onRefresh() { 
      swipeLayout.setRefreshing(true); 
      view.refreshDrawableState(); 
      swipeLayout.setRefreshing(false); 
     } 
    }); 

私はスワイプするたびにリストビューを更新するためにこれを行いますが、何も更新されません。

私のレイアウトは以下のように実装されます。

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

    <ListView 
     android:id="@+id/match_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:alpha="255"/> 

</android.support.v4.widget.SwipeRefreshLayout> 

それが動作しないのはなぜ?

+0

私は 'refreshDrawableState()'とは思っていません。そこにある 'Adapter'のデータセットを更新する必要があります。 –

答えて

0

リストビューアダプターに新しいリストを追加する必要があります。

private void refreshContent(){ 
    new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
     mAdapter = new ArrayAdapter<String>(MainActivity.this, 
     android.R.layout.simple_list_item_1, getNewTweets()); 
     mListView.setAdapter(mAdapter); 
     mSwipeRefreshLayout.setRefreshing(false); 
     }); 
} 
+0

これは 'setOnRefreshListener'内にありますか? – highuser1234

+0

はいアダプターから受け取ったリストを更新していません –

関連する問題