有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在不使用ID的情况下返回TextView。append()?

noobie在这里开发一个线性代数应用程序我的第一个应用程序,我正在尝试使用Textview。append()返回基于用户输入的一些计算。但既然我在用。对于我的打印方法,它会显示这些Id号

输出图像:http://imgur.com/Sb07Dtl

输出_ele由以下内容引用:

output_ele = (TextView)findViewById(R.id.outputLabel);

下面是我用来打印结果的方法

public final void stringprint(String[][] orig, int rowmax, int columnmax)
   {
   for (int i = 1; i <= rowmax; i++) {
       for (int j = 1; j <= columnmax; j++) {
           String entry = String.valueOf(orig[i][j]);

           String tab = "";

           for (int k = 1; k <= 7 - entry.length(); k++) {
               tab = tab + " ";
           }

           output_ele.append(output_ele + entry + tab);
       }

       output_ele.append(output_ele + "\n");
   }

这是点击按钮时运行的代码;它调用这些方法并将它们打印到output_ele标签上。此外,rowmax、columnmax和orig都在各自的方法中定义:

output_ele.append(output_ele + "Determinant: " + determinant(orig, rowmax, columnmax) + "\n");

    //roundmatrix(orig, rowmax, columnmax);
    //roundmatrix(transpose, columnmax, rowmax);

    output_ele.append(output_ele + "Row Reduced Echelon From: \n");
    //+= output_ele +  "Row Reduced Echelon Form: \n";
    stringprint(rationalize(orig, rowmax, columnmax), rowmax, columnmax);

    output_ele.append(output_ele + "\n");

    if ((rowmax == columnmax) && (determinant(orig, rowmax, columnmax) != 0))
    {
        output_ele.append("Inverse Matrix\n");
        stringprint(rationalize(inverse, rowmax, columnmax), rowmax, columnmax);
    }
    else
    {
        output_ele.append("Matrix is not invertible.\n");
    }

    output_ele.append("\nBasis of Rowspace:");
    output_ele.append(stringrowspace(rationalize(orig, rowmax, columnmax), rowmax, columnmax));

    output_ele.append("\nBasis of Columnspace:");
    output_ele.append( stringrowspace(rationalize(transpose, columnmax, rowmax), columnmax, rowmax));

    output_ele.append("\nBasis of Nullspace:");
    output_ele.append(nullspace(orig, rowmax, columnmax));

    output_ele.append("\nBasis of Left Nullspace:");
    output_ele.append(nullspace(transpose, columnmax, rowmax));
}

问题(我认为)是使用打印方法,我不希望那些讨厌的Id号码出现(如imgur链接所示)。我该怎么做呢

还有,当我有你在这里,什么是最简单的方法,使编辑文本文本框消失后,按下按钮

感谢您的帮助


共 (1) 个答案

  1. # 1 楼答案

    要从TextView中获取文本,应该使用output_ele.getText().toString(),如果将output_ele视为字符串,则可以获得所看到的所有对象信息

    例如

    output_ele.append(output_ele + "\n");
    

    应该是

    output_ele.append(output_ele.getText().toString() + "\n");
    

    但是,这将复制TextView的整个内容,您知道append将保留原始内容,并将append附加到它,对吗

    编辑

    进一步调查后,您的问题可能会通过删除粗体线条得到解决:

    输出_ele。追加(output_ele++“行列式:”+行列式(orig,rowmax,columnmax)+“\n”)

    输出_ele。追加(输出_ele+“行从:\n减少的梯队”)

    电子输出。追加(输出元素+“\n”)