Java – how does Android set a string array to a single textview

I want to try setting the string array to the text of textview How can I do this?

Here's what I've tried so far:

String[] word = { "Pretty","Cool","Weird" };

tv.setText( word.length );

But this can lead to some errors I'm new to Android / Java

Solution

word. Length gives the length of the array, not the contents You mean set the content to TV You can use the arrays#tostring method: –

String[] word = { "Pretty","Weird" };

// Prints [Pretty,Cool,Weird]
tv.setText(Arrays.toString(word));   

// Prints Pretty,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
分享
二维码
< <上一篇
下一篇>>