2012-12-06 29 views
1
<string name="text_9">This may not happen. If this happened, reset in 2&#8211;4 mins.</string> 

我用这样的:我们是否需要在Android中替换strings.xml文件中的逗号?

AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
alertDialog.setMessage(getResources().getText(R.string.text_9));  

的layout.xml看起来像

<LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingTop="15dp" > 

      <TextView 
       android:id="@+id/explain_label" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:textColor="#00000000" /> 
     </LinearLayout> 

显示的结果总是 “这可能不会发生。如果发生这种情况。” 逗号后的所有内容都没有显示出来。我试图用'\'和'\ u002c'替换逗号,但都不起作用。如果我删除逗号,则会显示所有内容。

如何替换逗号以取代完整描述?

+2

你的字符串很好。你在TextView中使用它吗?请发布其布局xml。 – brillenheini

+0

所以layout.xml是对话框的自定义布局?你如何使用它? – brillenheini

回答

1

请尝试调用create()方法之前设置的消息:

AlertDialog alertDialog = new AlertDialog.Builder(this) 
.setMessage(R.string.text_9) 
.create(); 
alertDialog.show(); 

或者与getString(R.string.text_9)更换getResources().getText(R.string.text_9)方法。

相关问题