Android: Access Textview Inside Child Of Expandablelistviewactivity
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 th
Solution 1:
You should override the getChildView
method of your ExpandableListAdapter
implementation, and inside of it set the text color based on any flag accessible to this adapter.
If the change is explicit, don't forget to call notifyDatasetChanged()
on the adapter after changing the flag!
To override the getChildView
method of a SimpleExpandableListAdapter
, you need to extend it (here anonymously):
finalSimpleExpandableListAdaptersa=newSimpleExpandableListAdapter(/*your list of parameters*/)
{
@Overridepublic View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
finalViewitemRenderer=super.getChildView(groupPosition,
childPosition, isLastChild, convertView, parent);
finalTextViewtv= (TextView)itemRenderer.findViewById(R.id.text);
if (/*check whether the data at groupPosition:childPosition is correct*/)
tv.setTextColor(getResources().getColor((R.color.green));
else
tv.setTextColor(getResources().getColor((R.color.red));
return itemRenderer;
}
};
Update
The problem in coloring lies in your resources file, you need to set the alpha value too for a text color, so your red should be #FFFF3523
, and your green: #FFA2CD5A
:
<resources><colorname="white">#ffffffff</color><colorname="myred">#FFFF3523</color><colorname="mygreen">#FFA2CD5A</color></resources>
Post a Comment for "Android: Access Textview Inside Child Of Expandablelistviewactivity"