Android: array of text views

I am creating an application in which I want to change the text of textviews from an array of strings. To do this, I need to create an array of text representations. How to do it? Can someone help me on this

+5
source share
4 answers

You can create TextViews as follows:

int textViewCount = 10;

TextView[] textViewArray = new TextView[textViewCount];

for(int i = 0; i < textViewCount; i++) {
   textViewArray[i] = new TextView(this);
}
+22
source

Maybe this is useful for you, I use a button array, so I work with text text like:

TextView[ ][ ]  _txt;   

_txt = new TextView[_dimension][_dimension]; // _dimension = 5 what you want
_txt[0][0] = (TextView) findViewById(R.id.text1);
_txt[0][1] = (TextView) findViewById(R.id.text2);

and much more...

+2
source

, , OutofBound,

LinearLayout parent = new LinearLayout(this);
        TextView textView;
        for( i = 0; i < count; i++) {
            textView = new TextView(this);
            textView.setTag(""+i);// setting tag with index i
            parent.addView(textView);
        }
        int len=parent.getChildCount();
        int j = 0;
        int requiredPosition = 5;
        while(j<len) {
            TextView tempTextView =((TextView)parent.getChildAt(i)); 
            if( tempTextView.getTag().equals(""+requiredPosition)){
                //Perform required operation
                //tempTextView.setText("");
            }
            j++;
        }
+2

:

int textvwCount = 20;//number of textview you want to use in an array

TextView[] arrTxtView = new TextView[textvwCount ]; // declare and assign array length of text views.

for(int i = 0; i < textViewCount; i++) { // iterate over all array items and assign them text.
  Textview txtCnt = new TextView(this);
txtCnt .settext(i);
 textViewArray[i] =txtCnt ;
}
+1

All Articles