I\'ve 16 textViews and need to set something like this done:
for (int i=1; i<6; i++)
{
int $RidInt = R.id.s;
tv[i] = (TextView)findViewById($RidI
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);
}
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);}}
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);
}