Android: Access TextView inside Child of ExpandableListViewActivity
-
02-11-2019 - |
Frage
I am using an ExpandableList via ExpandableListViewActivity.
Now, I would like to change the text colour of a certain TextView inside each ChildView. I don't want them all to be the same, rather something like "ok" in green and "error" in red etc.
I did stumble across getExpandableListAdapter().getChildView(...), but I'm unsure what the last parameters (View convertView, ViewGroup parent) are supposed to be. Also I don't quite know if I need to cast the return value (View) into something?
TextView tv = (TextView)this.getExpandableListAdapter().getChildView(0, 0, false, ???, ???).findViewById(R.id.xlist_child_tv);
Kind regards, jellyfish
Solution summary
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;
}
};
color resource:
<resources>
<color name="white">#ffffffff</color>
<color name="myred">#FFFF3523</color>
<color name="mygreen">#FFA2CD5A</color>
</resources>
Keine korrekte Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow