Select RecyclerView 中的所有复选框
Select all checkboxes in RecyclerView
如何 select recyclerView?
中的所有复选框
我试着这样做:
在适配器中:
public void selectAll(){
Log.e("onClickSelectAll","yes");
isSelectedAll=true;
notifyDataSetChanged();
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
PersonDTO item = dataSet.get(position);
holder.tvName.setText(item.getName());
if (!isSelectedAll) holder.cbSelect.setSelected(false);
else holder.cbSelect.setSelected(true);}
在 layout
Activity
我有一个 button
和 onClickListener
:
private void onClickSelectAll(View view) {
getSelectPersonsAdapter().selectAll();
}
你在这里犯了一个简单的错误
if (!isSelectedAll) holder.select_item.setChecked(false);
else holder.select_item.setChecked(true);
把setSelected
改成setChecked
就是这样
Select全部和全部取消选择
活动
checkall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(checkall.isChecked()){
categoryAdapter.selectAll();
}
else {
categoryAdapter.unselectall();
}
}
});
在适配器中
public void selectAll(){
isSelectedAll=true;
notifyDataSetChanged();
}
public void unselectall(){
isSelectedAll=false;
notifyDataSetChanged();
}
@Override
public void onBindViewHolder(@NonNull final MyviewHolder holder, int position) {
final CategoryListItems list = categoryListItems.get(position);
holder.text.setText(list.getName());
if (!isSelectedAll){
holder.checkbox.setChecked(false);
}
else holder.checkbox.setChecked(true);
如何 select recyclerView?
我试着这样做:
在适配器中:
public void selectAll(){
Log.e("onClickSelectAll","yes");
isSelectedAll=true;
notifyDataSetChanged();
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
PersonDTO item = dataSet.get(position);
holder.tvName.setText(item.getName());
if (!isSelectedAll) holder.cbSelect.setSelected(false);
else holder.cbSelect.setSelected(true);}
在 layout
Activity
我有一个 button
和 onClickListener
:
private void onClickSelectAll(View view) {
getSelectPersonsAdapter().selectAll();
}
你在这里犯了一个简单的错误
if (!isSelectedAll) holder.select_item.setChecked(false);
else holder.select_item.setChecked(true);
把setSelected
改成setChecked
就是这样
Select全部和全部取消选择
活动
checkall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(checkall.isChecked()){
categoryAdapter.selectAll();
}
else {
categoryAdapter.unselectall();
}
}
});
在适配器中
public void selectAll(){
isSelectedAll=true;
notifyDataSetChanged();
}
public void unselectall(){
isSelectedAll=false;
notifyDataSetChanged();
}
@Override
public void onBindViewHolder(@NonNull final MyviewHolder holder, int position) {
final CategoryListItems list = categoryListItems.get(position);
holder.text.setText(list.getName());
if (!isSelectedAll){
holder.checkbox.setChecked(false);
}
else holder.checkbox.setChecked(true);