如何以格式显示文本

时间:2014-02-24 07:25:32

标签: java android xml validation android-activity

    display a text in format  

    email.setText(text);
  1. 列出项目

    text =“1。如果你喝了液体并且吃了一顿诚实的饭,你就不会感到精疲力尽。”         +“2。捐献血液不会让你失去血液;实际上,即使在捐赠后你仍然可能有多余的血液。”         +“3。捐献血液时不会晕倒或感觉不舒服。这通常是一个典型的想法!”         +“4。如果献血,你不会得到艾滋病。”         +“5。如果你想喝酒,你将能够 - 连续一天。” + “”         +“将爱和礼物分享给最需要它的人。献血!”;

2 个答案:

答案 0 :(得分:2)

基本上\n会将内容打印到下一行。所以像下面一样使用它。

email.setText(text);
  text="1. You won’t feel drained or tired if you drink fluids and have an honest meal."
            +" \n 2. Donating blood won't leave you low of blood; in reality you            still may have surplus blood even after donation."
            +" \n 3. You will not faint or feel uncomfortable while donating blood. This is often a typical idea!"
            +" \n 4. You will not get AIDS if you donate blood."
            +" \n 5. If you want to consume alcohol, you'll be able to - on the consecutive day."
+""
            +" \n Share love and gift life to someone who needs it the most. Donate blood!";

答案 1 :(得分:1)

您的资源中的

执行以下操作:

<?xml version="1.0" encoding="utf-8"?>
 <resources>   
  <string        name="myMessage">1. You won’t feel drained or tired if you drink fluids and have an honest meal\n
2. Donating blood won't leave you low of blood; in reality you \n 
etc .. 
</string> 

</resources> 

然后在您的活动代码中引用它,如下所示:

email.setText(getString(R.string.myMessage)); 

请给我一些反馈

希望有助于。