In my code I have create recyclerview with check box and default one item selected already. now I want when select other item checkbox so deselect all other items mean one i
As you said, you are new to android first you will notice that your checkbox will have issues with recycler view.You selected some item in recycle view and after scrolling you will notice some other item is selected to solve this you need to follow this answer. or You need to create a boolean variable( to capture the state of checked checkbox for each item in recycler view)in your School Model class like this
class SchoolModel{
private boolean isChecked;
public boolean isChecked(){
return ischecked;}
public void setIsChecked(boolean checked){
isChecked = checked;
}
}
Second problem is to select only one checkbox and deselect rest of them for this you need write your logic(Check here for solution).And one major code change is to move your setOnCheckedChangeListener to view holder class because bindviewholder is called everytime you update your recyclerview and thus setting setOnCheckedChangeListener every time which is not correct.So you put this listener in view holder this will assign per checkbox listener only one time.
checkBoxDeleteComment.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//your code
}
});