小编ARQ*_*ttr的帖子

从Android中的ArrayAdapter访问资源

我定义了一些资源,例如:

<color name="lightGrey">#FFCCCCCC</color>
<integer name="KEY_POSITION_ARM">2</integer>
Run Code Online (Sandbox Code Playgroud)

...我有一个ArrayAdapter向TextViews显示项目.我正在尝试使用以下代码访问值:

keyPosition = getResources().getInteger(R.integer.KEY_POSITION_ARM);
moduleDataView.setTextColor(getResources().getColor(R.color.darkgreen));
Run Code Online (Sandbox Code Playgroud)

...但是我得到的错误是"方法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;
}
Run Code Online (Sandbox Code Playgroud)

第一种情况给出错误,第二种情况不会,但也不使用XML文件中的值.虽然正如你所说,我可以只使用R ...值,只要我在任何地方使用它.只是不确定这是否被认为是"最佳实践".谢谢

java android android-arrayadapter

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-arrayadapter ×1

java ×1