【发布时间】:2018-11-24 10:16:04
【问题描述】:
我有一个 ListView,其中包含多个位于自定义布局中的 TextView 项目。此列表是在运行时创建的,大小可能会有所不同。我为 ListView 使用了 SimpleAdapter
我想根据某些条件更改 TextViews 颜色。
我试过了,但它没有改变任何东西
LayoutInflater inflater = LayoutInflater.from(Measurements.this);
View view = inflater.inflate(R.layout.custom_row_view,null);
TextView before = (TextView)view.findViewById(R.id.before_t);
TextView after = (TextView)view.findViewById(R.id.after_t);
TextView fasting = (TextView)view.findViewById(R.id.fasting_t);
while (data.moveToNext()) {
if(data.getDouble(2)>110) before.setTextColor(Color.RED);
}
这是列表视图适配器
SimpleAdapter sa = new SimpleAdapter(this, list,
R.layout.custom_row_view,
new String[]{"line1", "line2", "line3", "line4"},
new int[]{R.id.date, R.id.before_t, R.id.after_t,R.id.fasting_t});
listview.setAdapter(sa);
您能指出解决方案吗?
【问题讨论】:
-
应该是
R.color.RED我想是的 -
您需要更改自定义适配器类中的颜色...您没有随问题发布。
-
不是自定义适配器@Barns
-
为什么会这样? @谷仓
-
因为您正在尝试引用一个视图,该视图显示在
ListView的行中,该行正在“幕后”构建,您需要在某些视图被创建时更改它们的属性已创建。
标签: android listview textview android-custom-view