【发布时间】:2011-05-10 09:54:30
【问题描述】:
我正在通过 ExpandableListViewActivity 使用 ExpandableList。
现在,我想更改每个 ChildView 中某个 TextView 的文本颜色。我不希望它们都一样,而是像绿色的“ok”和红色的“error”等。
我确实偶然发现了 getExpandableListAdapter().getChildView(...),但我不确定最后一个参数(View convertView、ViewGroup parent)应该是什么。另外我不太清楚是否需要将返回值(视图)转换成什么东西?
TextView tv = (TextView)this.getExpandableListAdapter().getChildView(0, 0, false, ???, ???).findViewById(R.id.xlist_child_tv);
亲切的问候, 水母
解决方案总结
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(...parameters...){
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
final View itemRenderer = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
final TextView tv = (TextView) itemRenderer.findViewById(R.id.kd_child_value);
if (tv.getText().toString().contentEquals(getString(R.string.true)))
{
tv.setTextColor(getResources().getColor(R.color.myred));
}
else if (tv.getText().toString().contentEquals(getString(R.string.false)))
{
tv.setTextColor(getResources().getColor(R.color.mygreen));
}
else
{
tv.setTextColor(getResources().getColor(R.color.white));
}
return itemRenderer;
}
};
颜色资源:
<resources>
<color name="white">#ffffffff</color>
<color name="myred">#FFFF3523</color>
<color name="mygreen">#FFA2CD5A</color>
</resources>
【问题讨论】:
标签: java android layout expandablelistview textcolor