Android 从自定义布局更改列表视图中调整的文本视图颜色
我有一个ListView,其中包含几个位于自定义布局中的TextView项。此列表是在运行时创建的,大小可以不同。我对ListView使用了SimpleAdapter 我想根据某些条件更改TextView的颜色 我试过这个,但没有改变任何事情Android 从自定义布局更改列表视图中调整的文本视图颜色,android,listview,textview,android-custom-view,Android,Listview,Textview,Android Custom View,我有一个ListView,其中包含几个位于自定义布局中的TextView项。此列表是在运行时创建的,大小可以不同。我对ListView使用了SimpleAdapter 我想根据某些条件更改TextView的颜色 我试过这个,但没有改变任何事情 LayoutInflater inflater = LayoutInflater.from(Measurements.this); View view = inflater.inflate(R.layout.custom_row_view,
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);
}
这是listview适配器
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);
您能指出解决方案吗?使用以下代码行:- 1> getColor(context,R.color.RED) 或 2> getActivity().getResources().getColor(android.R.color.white)
这行代码对我很有用。应该是
R.color.RED
我认为您需要更改自定义适配器类中的颜色…您没有随问题一起发布。这不是自定义的adapter@BarnsAnd为什么呢@Barns由于您试图引用一个视图,该视图显示在正在“幕后”构造的列表视图的行中,因此您需要在创建某些视图时更改其属性。