2017-08-07 43 views
0

該代碼在按鈕的onclick在活動:如何通過單擊按鈕選擇RecyclerView中的所有複選框?

if(v.getId()==recomendationSelectAllFriends.getId()){ 
    recomendationAdapter.selectAll(resultEntities.size()); 
} 

此方法在適配器:

public void selectAll(int size){ 
    // what should be written here? 
} 
+0

https://stackoverflow.com/questions/4876083/correct-way-to-check-all-checkboxes -in-listview檢查這一點 – AAA

回答

0
public void selectAll(int size){ 
    // what should be written here? 

    for(DataEntity e: data) { //your list of data in the array 
     e.isChecked(true) 
    } 
    notifyDataSetChanged(); 
} 

其中e.isChecked字段爲界,卡的複選框。

0

在您的模型類中添加一個布爾變量並將其命名爲該變量,併爲該變量寫入getter和setter。現在

, 在你onBindViewHolder寫

if(resultEntities.get(position).isChecked(){ 
    holder.yourCheckBoxName.setChecked(true); 
    }else{ 
holder.yourCheckBoxName.setChecked(false); 
} 

在你的函數

public void selectAll(){ 

    for(ResultEntity e: resultEntities) { 
     e.setChecked(true) 
    } 
    notifyDataSetChanged(); 
} 
相關問題