is there a way to make the following script more efficient? I want to make this code to be easy maintainable, thats why I'd like to get rid of the if else if's. I hope you guys can help me out here. In the bottom is something I would like to see, if its possible that way of course.
if (category.equals("infusion")){
layout.setBackgroundResource(R.color.infusion);
title.setText(R.string.title_infusion);
} else if (category.equals("pills")){
layout.setBackgroundResource(R.color.pills);
title.setText(R.string.title_pills);
} else if (category.equals("pumps")){
layout.setBackgroundResource(R.color.pumps);
title.setText(R.string.title_pumps);
} else if (category.equals("oxygen")){
layout.setBackgroundResource(R.color.oxygen);
title.setText(R.string.title_oxygen);
} else if (category.equals("scores")){
layout.setBackgroundResource(R.color.scores);
title.setText(R.string.title_scores);
} else if (category.equals("converters")){
layout.setBackgroundResource(R.color.converters);
title.setText(R.string.title_converters);
}
Something like this?
layout.setBackgroundResource(R.color.*category*);
title.setText(R.string.title_*category*);