我有字符串数组项,但对于每个元素的完成,我需要移至下一行。
String[] word = { "This is text1.So it should be single line", "This is text2", "This is text3" };
broadcastMessage.setText("" + Arrays.toString(word).replaceAll("\\[|\\]", ""));
但是这个输出显示为,
This is text1.So it should be single line ,this is text2,this is text3.
预期输出:(不应有逗号,并且应在下一行)。
This is text1.So it should be single line
This is text2
This is text3.
但是输出应该在每一行中。
最佳答案
试试这个
public class MainActivity extends AppCompatActivity {
String[] word = {"This is text1.So it should be single line", "This is text2", "This is text3"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textureView1);
for (int i = 0; i < word.length; i++) {
textView.append(word[i]);
textView.append("\n");
}
}
}
关于java - 如何将字符串数组带到 TextView 中的下一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49044577/