Java – how does Android set a string array to a single textview
•
Android
I want to try to set the string array to the text of textview. How can I do this@ H_ 419_ 1@
Here's what I've tried so far: @ h_ 419_ 1@
@H_ 419_ 1@
String[] word = { "Pretty", "Cool", "Weird" };
tv.setText( word.length );
But this will lead to some errors. I'm a novice of Android / Java @ H_ 419_ 1@
Solution: @ h_ 419_ 1@
Word.length gives the length of the array, not the content. You mean to set the content to TV. You can use the arrays#tostring method: – @ h_ 419_ 1@
@H_ 419_ 1@
String[] word = { "Pretty", "Cool", "Weird" };
// Prints [Pretty, Cool, Weird]
tv.setText(Arrays.toString(word));
// Prints Pretty, Cool, Weird
tv.setText(Arrays.toString(word).replaceAll("\\[|\\]", ""));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码