2016-01-30 10 views
15

मैंने रीसाइक्लर्विव के साथ स्वाइप रिफ्रेश लयआउट का उपयोग किया है, यह सभी एंड्रॉइड संस्करण में ठीक काम कर रहा है, लेकिन जब मैं नीचे खींचता हूं तो किटकैट में तब स्वाइप रिफ्रेश लेआउट लोडर नहीं जा रहा है और रीसाइक्लर्व डेटा को रीफ्रेश नहीं करता है लेकिन इसमें काम करता है लॉलीपॉपSwipeRefreshLayout लोडर ऊपर नहीं जा रहा है जब एंड्रॉइड

मैं 'com.android.support:support-v4:22.2.1'

संपादित उपयोग कर रहा हूँ 1

SwipeRefreshLayout swipe_refresh; 
swipe_refresh = (SwipeRefreshLayout)rootView.findViewById(R.id.swipe_refresh); 

swipe_refresh.post(new Runnable() { 
      @Override 
      public void run() { 
       swipe_refresh.setRefreshing(true); 
      } 
     }); 


swipe_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 
      @Override 
      public void onRefresh() { 
       // Loading more data.. 
       ..... 
       .... 
       getData(); 

      } 
     }); 

swipe_refresh.setColorSchemeResources(android.R.color.holo_blue_bright, 
       android.R.color.holo_green_light, 
       android.R.color.holo_orange_light, 
       android.R.color.holo_red_light); 

public void getData(){ 
    // Load data from web service... 
    ... 
    ... 
    ... 


    // After loading 
    swipe_refresh.setRefreshing(false); 

    // Set data to adapter 
} 

लेआउट कोड

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

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:background="@color/grey_100"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/gv_feeds" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="9" 
       android:scrollbars="vertical"/> 

      <ProgressBar 
      android:id="@+id/prog_load_more" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_gravity="center_horizontal" 
      android:visibility="gone"/> 

      </LinearLayout> 

     </FrameLayout> 

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

आप swipeRefreshLayout फोन करो। setRefreshing (गलत); डेटा लोड करते समय समाप्त हो गया है? –

+0

हाँ, मैं हूं .. जब मैं फिर से ताज़ा करने के लिए नीचे खींचता हूं तो यह स्क्रीन पर फंस जाता है, मैं इसे खींचकर खींच सकता हूं ... –

+0

क्या आप कोड संलग्न कर सकते हैं? –

उत्तर

0

आप इस तरह से

listView.setOnScrollListener(new OnScrollListener() { 

    @Override 
    public void onScrollStateChanged(AbsListView view, int scrollState) { 
    } 

    @Override 
    public void onScroll(AbsListView view, int firstVisibleItem, 
      int visibleItemCount, int totalItemCount) { 
     boolean enable = false; 
     if(listView != null && listView.getChildCount() > 0){ 
      // check if the first item of the list is visible 
      boolean firstItemVisible = listView.getFirstVisiblePosition() == 0; 
      // check if the top of the first item is visible 
      boolean topOfFirstItemVisible = listView.getChildAt(0).getTop() == 0; 
      // enabling or disabling the refresh layout 
      enable = firstItemVisible && topOfFirstItemVisible; 
     } 
     swipeRefreshLayout.setEnabled(enable); 
    }}); 
2

मैं पहले की तरह ही इस मुद्दे पड़ा है की कोशिश करो। ऐसा प्रतीत होता है जब आपके पास अपने रीसायकल व्यू को आपके स्वाइप रीफ्रेशलाइट के प्रत्यक्ष बच्चे के रूप में नहीं देखा जाता है। , तब

public class FixedSwipeRefreshLayout extends SwipeRefreshLayout { 

    private RecyclerView recyclerView; 

    public FixedSwipeRefreshLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public FixedSwipeRefreshLayout(Context context) { 
     super(context); 
    } 

    public void setRecyclerView(RecyclerView recyclerView) { 
     this.recyclerView = recyclerView; 
    } 

    @Override 
    public boolean canChildScrollUp() { 
     if (recyclerView!=null) { 
      return recyclerView.canScrollVertically(-1); 
     } 

     return false; 
    } 

} 

बजाय इस तरह android.support.v4.widget.SwipeRefreshLayout का उपयोग कर अपनी खुद की 'com.example.app.FixedSwipeRefreshLayout' का उपयोग की:

हम एक कस्टम का उपयोग करके इस समस्या का समाधान हो इस तरह SwipeRefreshLayout

<?xml version="1.0" encoding="utf-8"?> 
<com.example.app.FixedSwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/swipe_refresh" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
... 
</com.example.app.FixedSwipeRefreshLayout> 

और अंत में, जब आप अपने SwipeRefreshLayout की एक संभाल पाने के लिए, अपने कस्टम एक का उपयोग करें और अपने RecyclerView सेट:

FixedSwipeRefreshLayout swipe_refresh; 
swipe_refresh = (FixedSwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh); 
RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.gv_feeds); 
swipe_refresh.setRecyclerView(mRecyclerView); 

उम्मीद है कि यह मदद करता है।

1

के अनुसार swipeRefreshDocumentation SwipeRefreshLayout लेआउट कि स्क्रॉल करता है, तो इसके अंदर जोड़ा नहीं हैं के साथ अच्छी तरह से नहीं चलता है: आप इस के लिए 2 समाधान है:

1) recyclerView के रूप में प्रत्यक्ष बच्चे के लिए swipeRefreshLayout बनाने के लिए अपने लेआउट बदल जाते हैं।

कुछ इस तरह:

<?xml version="1.0" encoding="utf-8"?> 

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:id="@+id/ll_HeaderProgress" 
     android:background="@color/white_color_30"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
      <android.support.v4.widget.SwipeRefreshLayout 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/swipe_refresh" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="9" 
       > 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerview_buzz" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical"/> 
</android.support.v4.widget.SwipeRefreshLayout> 
      <ProgressBar 
       android:id="@+id/ll_footerProgress" 
       android:layout_width="40dp" 
       android:layout_height="40dp" 
       android:layout_gravity="center_horizontal" 
       android:visibility="gone"/> 
     </LinearLayout> 
    </FrameLayout> 

2) श्रोता साथ SwipeRefreshLayout बढ़ाएँ वर्गों है कि इस लेआउट प्रदर्शित से विभिन्न स्थितियों को जोड़ने के लिए सक्षम होने के लिए।

कुछ निम्नलिखित की तरह: RefreshSwipeRefreshLayout.java

public class RefreshSwipeRefreshLayout extends SwipeRefreshLayout { 
    private OnChildScrollUpListener mScrollListenerNeeded; 

    public interface OnChildScrollUpListener { 
    boolean canChildScrollUp(); 
    } 

    public RefreshSwipeRefreshLayout(Context context) { 
    super(context); 
    } 
    public RefreshSwipeRefreshLayout(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    } 

/** 
    * Listener that controls if scrolling up is allowed to child views or not 
    */ 
    public void setOnChildScrollUpListener(OnChildScrollUpListener listener) { 
    mScrollListenerNeeded = listener; 
    } 

    @Override 
    public boolean canChildScrollUp() { 
    if (mScrollListenerNeeded == null) { 
     Log.e(GeneralSwipeRefreshLayout.class.getSimpleName(), "listener is not defined!"); 
    } 
    return mScrollListenerNeeded != null && mScrollListenerNeeded.canChildScrollUp(); 
    } 
} 

और फिर कक्षा SwipeRefreshLayout recyclerView लेआउट युक्त प्रदर्शित करता है कि में ऐसा करते हैं, आप कुछ इस तरह कर सकते हैं:

mSwipeLayout.setOnChildScrollUpListener(new OnChildScrollUpListener() { 
    @Override 
    public boolean canChildScrollUp() { 
    return ((LinearLayoutManager)mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition().getFirstVisiblePosition() > 0 || 
      mRecyclerView.getChildAt(0) == null || 
      mRecyclerView.getChildAt(0).getTop() < 0; 
    } 

});

भी एक्सएमएल

0

में इसे बदलने के लिए भूल जाते हैं न मैं इस जवाब देने के लिए देर से हो सकता है, लेकिन मैं एक ही मुद्दा मिला है, सब मैंने किया था जोड़ने के लिए है:

swipe_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 
    @Override 
    public void onRefresh() { 
     // Loading more data.. 
     ..... 
     .... 
     getData(); 

     //make sure to set it to false as this will be set it to true when onRefresh is triggered 
     swipe_refresh.setRefreshing(false); 
    } 
}); 
संबंधित मुद्दे