2017-01-02 96 views
0

我要求一次在列表中顯示10個元素。加載10個元素後,用戶將擁有「加載更多結果」按鈕。點擊這個按鈕,它將從服務器獲取另外10個元素。如果最初總數沒有。的元素少於10,它不應該顯示「加載更多結果」按鈕。帶有「加載更多結果」按鈕的回收站視圖

所以,我想開發這個使用Recycler View,但我無法做到這一點。 請指導我。

由於提前

+2

'「但我不能夠做到這一點」'所以你嘗試過這麼遠嗎? – pskink

+0

先加在數組列表10個項目,點擊加載後更多結果增加10多個項目到數組列表,並做'adapter.notifyDataSetChanged()' – Redman

+0

@Redman感謝您的建議 –

回答

0

在你的xml中使loadButton可見性消失。

在您的活動類,當你設置數據的API回調方法適配器,只需檢查

if(list.size()>=10) { 
    loadButton.setVisibility(VISIBLE); 
    } else { 
    loadButton.setVisibility(GONE); 
    } 
+0

感謝變化回答 –

+0

如果解決了問題,請將其標記爲正確答案@AbdulRahaman –

0

RecyclerView.OnScrollListener

首先實現你的recyclerview OnScrollListener。您可以從滾動偵聽器中獲取最後一項,並放置一個名爲LOAD MORE的按鈕。當你得到RecyclerView的最後一項時,使它可見。

+0

感謝 –

+0

謝謝@Vikas的 –

0

你可以像這樣的東西開始。

<android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:nestedScrollingEnabled="false" /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Load More" 
       android:visibility="visible" /> 

     </LinearLayout> 


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

實現邏輯給你;)