Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用空格替换按钮内的字符串_Java_Android_Android Layout_Android Relativelayout - Fatal编程技术网

Java 用空格替换按钮内的字符串

Java 用空格替换按钮内的字符串,java,android,android-layout,android-relativelayout,Java,Android,Android Layout,Android Relativelayout,我正在做一个琐事游戏,答案由角色组成,每个角色都在一个按钮上 当我在答案中添加空格时,它不会显示为空白,而是显示为空按钮“字符” 我尝试替换java文件“sceneactivity”中的字符,这样当答案由两个单词“space”组成时,它会直接创建一个带有“\n”的新行 但什么也没发生,“\n”被认为是一个字符,也是可能的答案字母的一部分 这就是代码的样子 // draw word buttons RelativeLayout wordLayout = (Relative

我正在做一个琐事游戏,答案由角色组成,每个角色都在一个按钮上

当我在答案中添加空格时,它不会显示为空白,而是显示为空按钮“字符” 我尝试替换java文件“sceneactivity”中的字符,这样当答案由两个单词“space”组成时,它会直接创建一个带有“\n”的新行 但什么也没发生,“\n”被认为是一个字符,也是可能的答案字母的一部分

这就是代码的样子

        // draw word buttons

    RelativeLayout wordLayout = (RelativeLayout) findViewById(R.id.wordlayout);
    String[] word = ld.getLevelSpecific().getProcessedWord();
    for (int i = 0; i < word.length; i++) {
        Button temp = new Button(this);
        word[i] = word[i].replace(" "\\s"\n");
        word[i] = word[i].replaceAll(" ", "\n");

        temp.setText(""); ......................
//绘制单词按钮
RelativeLayout wordLayout=(RelativeLayout)findViewById(R.id.wordLayout);
字符串[]word=ld.getLevelSpecific().getProcessedWord();
for(int i=0;i
" 我想要的是排除空格,我不希望它被认为是答案的一部分,只是一个空白或一行新词


谢谢

请尝试使用下面的代码而不是
\n

word[i] = word[i].replace(" ", System.getProperty("line.separator"));
或使用此选项删除所有空白和不可见字符:

word[i] = word[i].replaceAll("\\s","")