I am making an app in which I want to change the text of textviews from an array of strings. For that I need to make the array of textviews.How to do that?? Can anyone help me over this
Go to app > res > layout > right-click > New > Layout Resource File and create a new layout file and name this file as item_view. xml and make the root element as a LinearLayout. This will contain a TextView that is used to display the array objects as output.
With Android 8.0 (API level 26) and higher, you can instruct a TextView to let the text size expand or contract automatically to fill its layout based on the TextView 's characteristics and boundaries. This setting makes it easier to optimize the text size on different screens with dynamic content.
A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.
Go to File -> Settings, a new setting dialogue box will appear. Then go to Editor -> General. Now mark the checkbox Change font size with Ctrl + Mouse wheel and click on Apply button. Now to change your editor font size, you just have to press and hold Ctrl and rotate the Mouse wheel.
You can create TextViews like this:
int textViewCount = 10;
TextView[] textViewArray = new TextView[textViewCount];
for(int i = 0; i < textViewCount; i++) {
textViewArray[i] = new TextView(this);
}
If you want large number of textviews, in that case to avoid OutofBound exception use following code
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++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With