2
Is there any other way to accomplish this code?
This code is very repetitive, I wanted to know if it is possible to decrease and make easier the understanding.
if (games.getBallId() == btnBal0l.getId()){
btnBal0l.setBackgroundResource(R.mipmap.ball_verde);
}else if (games.getBallId() == btnBal02.getId()){
btnBal02.setBackgroundResource(R.mipmap.ball_verde);
}else if (games.getBallId() == btnBal03.getId()){
btnBal03.setBackgroundResource(R.mipmap.ball_verde);
}else if (games.getBallId() == btnBal04.getId()){
btnBal04.setBackgroundResource(R.mipmap.ball_verde);
}else if (games.getBallId() == btnBal05.getId()){
btnBal05.setBackgroundResource(R.mipmap.ball_verde);
}else if (games.getBallId() == btnBal06.getId()){
btnBal06.setBackgroundResource(R.mipmap.ball_verde);
}else if (games.getBallId() == btnBal07.getId()){
btnBal07.setBackgroundResource(R.mipmap.ball_verde);
}
It can be improved with
switch { case: }
, but it would get bigger– adventistaam