Android将R.String.xx值传递给字符串构建器

时间:2014-10-08 12:11:01

标签: android stringbuilder

字符串值到字符串构建器但我无法获取值

builder.append("<tr align=center bgcolor=#9d8a2e><th colspan=2 height="
                        + tableHeight
                        + " width="
                        + tableWidthLeft
                        + **R.string.useonly**
                        + "</th><th align=right  height="
                        + tableHeight
                        + " width="
                        + tableWidthRight
                        + ">"
                        + Provider.im_rad + "" + "</th></tr>");

我想传递 R.string.useonly 但是它不起作用.....但当我这样做时,它正在工作

builder.append("<tr align=center bgcolor=#9d8a2e><th colspan=2 height="
                        + tableHeight
                        + " width="
                        + tableWidthLeft
                        + ">for use only purpose"
                        + "</th><th align=right  height="
                        + tableHeight
                        + " width="
                        + tableWidthRight
                        + ">"
                        + Provider.im_rad+ "" + "</th></tr>");

3 个答案:

答案 0 :(得分:3)

要获取字符串资源,您应该使用

getResources().getString(R.string.your_text); 

如果你在片段上调用它,你应该在开头添加getActivity()

答案 1 :(得分:2)

  

使用此:getString(int)

 builder.append("<tr align=center bgcolor=#9d8a2e><th colspan=2 height="
                    + tableHeight
                    + " width="
                    + tableWidthLeft
                    + getResources().getString(R.string.useonly))
                    + "</th><th align=right  height="
                    + tableHeight
                    + " width="
                    + tableWidthRight
                    + ">"
                    + Provider.im_rad + "" + "</th></tr>");

答案 2 :(得分:1)

您可以通过调用Context(例如ActivitygetString(resId).

来获取资源ID的字符串