How do I iterate through the id properties of R.java class?

Solution 1:

Something like that?

import java.lang.reflect.Field;
/* ... */

for (int i = 1; i < 16; i++) {
    int id = R.id.class.getField("s" + i).getInt(0);
    tv[i] = (TextView)findViewById(id);
    tv[i].setTypeface(face);
    tv[i].setClickable(true);
    tv[i].setOnClickListener(clickListener);
}

Solution 2:

try this.

public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);
            LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout01);
            for (int i = 0; i < ll.getChildCount(); i++) {
                ((TextView) ll.getChildAt(i)).setText("Text View " + i);
            }

Solution 3:

I had to wrap mine in a try/catch wrapper, not sure why, but I'm Very New.

for (int counter = 1; player < 5; counter++) {
        try {Field field = example.main.R.id.class.getField("s" + counter);
             try {screenid = field.getInt(null);} 
            catch (IllegalAccessException e){//exceptioncodehere}
        catch (NoSuchFieldException e) {//exception2codehere}
        TextView SetMe = (TextView)findViewById(screenid);
        SetMe.setText("Text" + player);}}