gpt4 book ai didi

android - 在 Android TextView 中,是否可以插入段落?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:59:08 24 4
gpt4 key购买 nike

下面是我遇到的问题类型的示例。我在 pojo 中有数据需要在 TextView 中显示...数据具有伪代码,用 [p]

表示每个段落

当 [p] 在 TextView 中显示时,我想以某种方式将它们解析为段落。这可以做到吗?有什么东西可以代替 [p] 来在 TextView 中创建一个新段落吗?

Question question = new Question();
question.setText("Here is the first paragraph.[p] And this should be the second.");

TextView view = (TextView) findViewById(R.id.qtext);
view.setText(question.getParsedText());

最佳答案

您好,我会解析整个字符串,然后根据需要用\n 甚至\n\n 替换每个 [p]。

\n 在字符串中换行。例如像这样使用它:

question.setText("Here is the first paragraph.\n\n And this should be the second.");`

可以轻松做到这一点的方法是 String.replace(...)

关于android - 在 Android TextView 中,是否可以插入段落?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2979433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com