Im working on a project on Android Studio and I
m trying to create a filter. I added some check boxes to it and I would like to filter my RecyclerView with it. With IF statement I can do it, but as I understand for many IF ELSE statements is better to use SWITCH case. Therefore I would like to change my IF statement to SWITCH case but I don`t know how to implement this method in Android Studio.
There is the code:
btnApply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {
if(check_spring.isChecked() && check_summer.isChecked() && check_autumn.isChecked() && check_winter.isChecked())
{
addAllplaces();
}
else if (check_spring.isChecked() && check_summer.isChecked() && check_autumn.isChecked())
{
removeAllplaces();
addSpring();
addSummer();
addAutumn();
removeWinter();
}
And I would like to use like this:
@Override public void onClick(View view) { boolean checked = ((CheckBox) view).isChecked();
switch (view.getId()) {
case R.id.check_spring:
if (checked) {
removeAllplaces();
addSpring();
removeSummer();
removeAutumn();
removeWinter();
} else
addAllplaces();
removeSpring();
removeSummer();
removeAutumn();
removeWinter();
break;
Aucun commentaire:
Enregistrer un commentaire