java - 如何将字符串数组带到 TextView 中的下一行?

标签 java android string replace

我有字符串数组项,但对于每个元素的完成,我需要移至下一行。

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/

相关文章:

java - 如何在 Android Studio Camera2 中找到相机百万像素

java - Hibernate 看不到映射 xml 文件

android - 为什么 GreenDao 中的 queryRaw 方法不返回惰性列表?

Android Emulator 在硬件加速下不启动,linux/ubuntu

javascript - 如何将对象值插入到公式中?

PHP:如何从字符串中删除特殊字符(某些除外)

javascript - window.location.reload() 在我的 js 页面中使用 我正在注销 我正在使用 spring security

java |带有 ^M 的 CSV 问题

android - 使用 IBM 示例将 Xml 解析为 android ListView

java - 如何将字符串转换为数组?