拆分一个字符串,使文本位于彼此下方

发布于 2025-01-04 06:53:43 字数 674 浏览 1 评论 0原文

我有一个字符串,它将被我的下一堂课中的intentExtra 拾取,并设置为多行TextView 的文本。我想知道是否有一种方法可以将文本分开,这样它们就在彼此的下面,所以我有这个字符串:

maint = "Here is some info about nothing." +
                "Some more info about nothing." +
                "And a little more about nothing";

所以通常它们会显示在像这样的文本视图中:

Here is some info about nothing. Some more info about nothing. And a little more info about nothing.

有没有一种方法可以让它们在每个文本之后结束该行这些单独的片段被写入 TextView 中,

如下所示:

Here is some info about nothing.
Some more info about nothing.
And a little more about nothing.

对于每个单独的句子来说,使用单独的 TextView 似乎太多了。

提前致谢

i have a string that will get picked up by an intentExtra in my next class and be set as the text for a multiline TextView. i was wodnering if there is a way to split the text up so they are under eachother, so i have this string:

maint = "Here is some info about nothing." +
                "Some more info about nothing." +
                "And a little more about nothing";

so usually they would be displayed in a textView like this:

Here is some info about nothing. Some more info about nothing. And a little more info about nothing.

is there a way so they would end the line after each one of those separate pieces were written into the TextView

like so:

Here is some info about nothing.
Some more info about nothing.
And a little more about nothing.

it just seems like it would be too much with a separate TextView for each of those separate sentences.

thanks in advance

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

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

发布评论

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

评论(2

彼岸花似海 2025-01-11 06:53:43

在要换行的位置添加 /n。

maint = "Here is some info about nothing.\n" +
        "Some more info about nothing.\n" +
        "And a little more about nothing";

您还可以使用 Html 对其进行格式化。在您想要换行的位置添加一个。

maint = "Here is some info about nothing.</br>" +
        "Some more info about nothing.</br>" +
        "And a little more about nothing";

如果使用 HTML 格式,则需要先解析它,然后再将其传递给 textview:

myTextView.setText(Html.fromHtml(maint));

Add a /n to where you want to have a newline.

maint = "Here is some info about nothing.\n" +
        "Some more info about nothing.\n" +
        "And a little more about nothing";

You could also format it using Html. Add a where you want a newline.

maint = "Here is some info about nothing.</br>" +
        "Some more info about nothing.</br>" +
        "And a little more about nothing";

If you format it with HTML, you need to parse it first before passing it to the textview:

myTextView.setText(Html.fromHtml(maint));
一袭白衣梦中忆 2025-01-11 06:53:43

这应该做你想要的(“\n”是换行符)

maint = "Here is some info about nothing.\n" +
                "Some more info about nothing.\n" +
                "And a little more about nothing\n";

This should do what you want ("\n" being a newline character)

maint = "Here is some info about nothing.\n" +
                "Some more info about nothing.\n" +
                "And a little more about nothing\n";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文