【发布时间】:2012-01-03 07:09:21
【问题描述】:
我定义了一些资源,例如:
<color name="lightGrey">#FFCCCCCC</color>
<integer name="KEY_POSITION_ARM">2</integer>
...我有一个 ArrayAdapter 向 TextViews 显示项目。我正在尝试使用以下代码访问值:
keyPosition = getResources().getInteger(R.integer.KEY_POSITION_ARM);
moduleDataView.setTextColor(getResources().getColor(R.color.darkgreen));
...但我收到类似“方法 getResources() 未定义类型 ContinuityAdapter”的错误。 (ContinuityAdapter 扩展了 ArrayAdapter)
有什么好的办法吗?
谢谢
这是一个例子:
switch (currentModule.keyPosition) {
case activity.getResources().getInteger(R.integer.KEY_POSITION_ARM):
moduleDataView.keyPosition.setText("TEST");
moduleDataView.keyPosition.setTextColor(Color.GREEN);
break;
case R.integer.KEY_POSITION_ARM:
moduleDataView.keyPosition.setText("ARM");
moduleDataView.keyPosition.setTextColor(Color.RED);
break;
}
第一种情况给出错误,第二种情况没有但也不使用 XML 文件中的值。尽管正如您所说,只要我在任何地方都以这种方式使用它,我就可以使用 R... 值。只是不确定这是否被认为是“最佳实践”。谢谢
【问题讨论】:
标签: java android android-arrayadapter