【问题标题】:Add new line character in string [duplicate]在字符串中添加换行符[重复]
【发布时间】:2013-05-12 04:21:31
【问题描述】:

如何在每个文本后换行??

这是代码。

String body = txtName.getText().toString() + txtLatitude.getText().toString() + txtLongitude.getText().toString();
ii.putExtra(android.content.Intent.EXTRA_TEXT, body);

我尝试只使用\n,但它给了我错误。请帮帮我。

【问题讨论】:

  • 其中有什么错误? \n 适用于换行文本。
  • 请将 + 替换为 +"\n"+。

标签: android textview newline


【解决方案1】:
String body = txtName.getText().toString() + "\n" + txtLatitude.getText().toString() + "\n" + txtLongitude.getText().toString();

【讨论】:

  • 我认为它应该是完美的。使用 "\n" 换行,但介于 + "\n" + 之间。
【解决方案2】:

你可以像这样在你的字符串中使用 html 标签。

String body = Html.fromHtml(txtName.getText().toString()+"<br />"
                    + txtLatitude.getText().toString()+"<br />"
                    + txtLongitude.getText().toString()+"<br />");

【讨论】:

    【解决方案3】:

    我认为您使用的是 android java。不确定,但在 c++ 中,您可以使用 std 库中的 endl 函数。我认为有一个类似的功能,system.getproperty("line.separator") 或 ("line.new") 你可以尝试一下,它接近这个。另外由于 "\n" 不起作用,请尝试使用单引号 '\n' 它是换行符,因此它可能算作 java 中的单个字符。除此之外
    也可以工作,它是标准的 HTML。

    【讨论】:

    • aka string = blah + System.getProperty("line.seperator") + blah;
    猜你喜欢
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2012-05-18
    • 2014-12-01
    • 1970-01-01
    相关资源
    最近更新 更多