开发者

Change Text Color in ExpandedListView, when list is expanded

I have a expandedlistview and I开发者_开发百科 want to change the textcolor of group when the particular group is expanded. I tried many things but not able to find solution.Please let me know if there is any solution for this


In the adapter you're using you should be overriding the getGroupView() method. One of the parameters you get is an isExpanded boolean value. Just use that value to decide what color to set the textview in question. Here is an example:

@Override
public void getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    // Here you would do your convertView initialization
    // ...
    TextView textView = (TextView) convertView.findViewById(R.id.textview);
    if(isExpanded)
        textView.setTextColor(/* some color */);
    else
        textView.setTextColor(/* some other color */);
    // Do the rest of your view binding
    //...
}


Here is code :

@Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
            View parentView = ( View )convertView.findViewById( R.id.settings_menu );
            parentView.setBackgroundResource( R.drawable.background1 );

            TextView parentTextView = ( TextView )convertView.findViewById( R.id.menu_title );
            parentTextView.setText( groups[ groupPosition ].toString() );

            if( isExpanded ){
                convertView.setBackgroundResource( R.drawable.settings_background2 );
                parentTextView.setTextColor( R.color.black);
            }

            return convertView ;
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜