6

我正在运行一个TabActivity. 在以下行中:

spec = tabHost.newTabSpec("alltime").setIndicator(R.string.plots_allTime)
       .setContent(intent);

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

4

2 回答 2

17
spec = tabHost.newTabSpec("alltime").setIndicator(getString(R.string.plots_allTime))
.setContent(intent);
于 2010-11-06T19:58:39.463 回答
11

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

setIndicator(context.getText(R.string.plots_allTime) )
于 2010-11-06T19:57:51.887 回答