以下是我遇到的问题类型的示例。我在 pojo 中有数据,需要在文本视图中显示...该数据具有伪代码,用 [p] 表示每个段落
当它们显示在文本视图中时,我想以某种方式将 [p] 解析为段落。这可以做到吗?有什么东西可以代替 [p] 来在文本视图中创建一个新段落吗?
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());
嗨,我会解析整个字符串,然后根据需要将每个 [p] 替换为 \n 甚至 \n\n 。
字符串中的 \n 会产生换行符。例如这样使用它:
question.setText("Here is the first paragraph.\n\n And this should be the second.");`
可以轻松做到这一点的方法是字符串.replace(...)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)