Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改ExponebleListView的组颜色在android中效果不佳_Android_Expandablelistview - Fatal编程技术网

更改ExponebleListView的组颜色在android中效果不佳

更改ExponebleListView的组颜色在android中效果不佳,android,expandablelistview,Android,Expandablelistview,您好,我使用此代码来更改组的背景,当用户单击该组时,该组已关闭 expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v,

您好,我使用此代码来更改组的背景,当用户单击该组时,该组已关闭

expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

            @Override
            public boolean onGroupClick(ExpandableListView parent, View v,
                                        int groupPosition, long id) {
                if (!parent.isGroupExpanded(groupPosition)) {
                    v.setBackgroundColor(Color.parseColor("#ff9600"));
                } else  {
                    v.setBackgroundColor(Color.parseColor("#4fc1e9"));

                }
                if (parent.isGroupExpanded(groupPosition)) {
                    Toast.makeText(AdieActivity.this,String.valueOf( groupPosition), Toast.LENGTH_SHORT).show();
                }


                return false;
            }
        });

当用户单击并选择组时,背景颜色会改变,但问题是,一些组没有打开,但背景也会改变。覆盖的方法包含在我的自定义ExpandableListAdapter中

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
    View view, ViewGroup parent)
{
     LinearLayout bevGroup = (LinearLayout) view.findViewById(R.id.myid);

if(isExpanded)
{
    bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgGroupBlack));
}
else
{
    bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgTransparent));
}
}

重写的方法包含在自定义ExpandableListAdapter中

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
    View view, ViewGroup parent)
{
     LinearLayout bevGroup = (LinearLayout) view.findViewById(R.id.myid);

if(isExpanded)
{
    bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgGroupBlack));
}
else
{
    bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgTransparent));
}
}

我在扩展BaseExpandableListAdapter类中使用视图,如果(isExpanded){convertView.setBackgroundResource(R.color.select);}或者{convertView.setBackgroundResource(R.color.focuse);}我在扩展BaseExpandableListAdapter类中使用视图,如果(isExpanded)也可以使用视图{convertView.setBackgroundResource(R.color.select);}其他{convertView.setBackgroundResource(R.color.focuse);}我想,我必须在@Override public View getGroupView上写代码,而不是在expListView中。setOnGroupClickListener和它工作我想,我必须在@Override public View getGroupView上写代码,而不是在expListView中。setOnGroupClickListener和它工作