【发布时间】:2011-12-10 01:16:03
【问题描述】:
我正在实现一个 Android 活动。 我在我的应用程序布局中使用 ListView,并在继承的 SimpleAdapter getView 中通过 setBackgroundResource 设置视图颜色。
public class SpecialAdapter extends SimpleAdapter {
public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
super(context, items, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (mSensorsStatus[position].equals(mSensorStatus[SENSOR_STATUS_ALERT])) {
view.setBackgroundResource(R.color.red);
}
else if (mSensorsStatus[position].equals(mSensorStatus[SENSOR_STATUS_ARMED])) {
view.setBackgroundResource(R.color.light_grey);
}
return view;
}
}
我的问题是,当我单击其中一个项目时,它没有像通常那样以黄色/橙色着色(删除 setBackgroundResource 时它工作正常)
更多信息: 我尝试通过 mListView.getChildAt(index).setBackgroundResource(R.color.red) 而不是设置背景颜色 getView 实现,结果是一样的。
感谢您的帮助
【问题讨论】:
-
呃,你用的是什么语言?什么 GUI 工具包?
-
抱歉,忘了说这是一个 Android 活动...