Initialize them as follows:
TextView[] tv = new TextView[48];
Then you can set the text in them using the for loop as follows:
for(int i=0; i<48; i++) { tv[i].setText("your text"); }
EDIT: In your XML file, provide identical identifiers for all text views. E.g. tv0, tv1, tv2, etc. Initialize a string array that will have these identifiers as a string.
String ids[] = new String[48]; for(int i=0; i<48; i++) { ids[i] = "tv" + Integer.toString(i); }
Now, to initialize the TextView array, do the following:
for(int i=0; i<48; i++) { int resID = getResources().getIdentifier(ids[i], "id", "your.package.name"); tv[i] = (TextView) findViewById(resID); }
source share