Android开发:如何在使用setText()时自动添加换行符?

发布于 2024-09-25 22:01:10 字数 347 浏览 0 评论 0原文

我的应用程序具有读取文件的功能。 这工作得很好,但是有一个问题。 当我将文件的内容附加到我的大 EditText 时,不会添加换行符或任何名称,因此:

function hmm(){
 echo 'Hello, PHP!';
}

会变成这样:

function hmm(){ echo 'Hello, PHP!'; }

如何停止此操作并使其出现在 EditText 中,就像文件中出现的那样?

更新: 真的很抱歉浪费了您的时间,我很愚蠢,没有考虑在 while 循环附加每一行后添加“\n”。

In my app is the ability to read a file.
This works perfectly, but there's a problem.
No line breaks or whatever they are called get added when I append the file's contents to my big EditText, so this:

function hmm(){
 echo 'Hello, PHP!';
}

would turn into this:

function hmm(){ echo 'Hello, PHP!'; }

How can I stop this and make it appear in the EditText as it appears in the file?

UPDATE:
REALLY sorry for wasting your time, I went stupid and didn't think about adding "\n" after the while loop has appended each line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无敌元气妹 2024-10-02 22:01:10

问题已解决。

基本上,在用于输出每一行的 while 循环中,您需要附加换行符 (\n),如下所示:

     while (dis.available() != 0) {
      textBox.append(dis.readLine() + "\n");
     }

TextBox 是 Android EditText。

这将使 EditText 看起来与您选择的文件中的文本完全相同。

Problem solved.

Basically in the while loop that's used to output each line you need to append a line break (\n) like so:

     while (dis.available() != 0) {
      textBox.append(dis.readLine() + "\n");
     }

With textBox being an Android EditText.

This will make the EditText look exactly as the text does in the file you selected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文