strings.xml的问题...无法将R.string.foo作为CharSequence传递

dfe*_*r88 5 java android charsequence

我正在跑步TabActivity.在以下行中:

spec = tabHost.newTabSpec("alltime").setIndicator(R.string.plots_allTime)
       .setContent(intent);
Run Code Online (Sandbox Code Playgroud)

我得到一个错误,因为setIndicator()期望一个CharSequence.我不确定如何解决这个问题,因为我应该能够将字符串传递给该参数.我认为问题在于生成R.javastrings.xml文件初始化文件中的所有内容public static final int.setIndicator()方法似乎不太喜欢.有没有办法解决?

Pet*_*ego 16

spec = tabHost.newTabSpec("alltime").setIndicator(getString(R.string.plots_allTime))
.setContent(intent);
Run Code Online (Sandbox Code Playgroud)


Asa*_*ahi 10

您需要从R.string获取与ID相对应的字符串:use context.getText,它从应用程序包的默认字符串表返回一个本地化的样式化CharSequence:

setIndicator(context.getText(R.string.plots_allTime) )
Run Code Online (Sandbox Code Playgroud)