I need to create a series of objects, and it just looks plain ugly right now:
CheckBox checkOne = (CheckBox) findViewById(R.id.checkOne);
CheckBox checkTwo = (CheckBox) findViewById(R.id.checkTwo;
CheckBox checkThree = (CheckBox) findViewById(R.id.checkThree);
CheckBox checkFour = (CheckBox) findViewById(R.id.checkFour);
CheckBox checkFive = (CheckBox) findViewById(R.id.checkFive);
I’m on an intermediate level when it comes to Java, so what I wanted to do was to do a for loop and then use variable variables. Alas, Java does not support this. Is there any, less recursive, way to do this?
Assuming the lookup keys are ints, you can do it like this:
If the keys are something else, you’ll of course need to change the type of the
idsarray.And if you have control over how these keys are held in the
Rclass, you might better just make them an array there.You might also be better off using Lists instead of arrays.