2017-12-10 5 views
0

ListView가 포함 된 내 조각 중 하나에 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); 
     } 
    }); 

내가 스 와이프 때마다 내 ListView를 새로 고치기 위해이 작업을 수행하지만 아무 것도 업데이트되지 않습니다.

내 레이아웃은 다음과 같이 구현됩니다

<?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

예 어댑터에서받은 목록을 업데이트하지 않았습니다. –

관련 문제