Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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
Java 选择新列表项时更改背景色-Android_Java_Android_Expandablelistview_Onclicklistener_Background Color - Fatal编程技术网

Java 选择新列表项时更改背景色-Android

Java 选择新列表项时更改背景色-Android,java,android,expandablelistview,onclicklistener,background-color,Java,Android,Expandablelistview,Onclicklistener,Background Color,已更新 我想将所选菜单项的背景色更改为淡蓝色。单击时会发生颜色更改,但我仍然无法将上一个菜单项返回到旧颜色(以显示它不再被选中)。下面是我取得的进展,但仍有不足之处 这正是我试图实现的目标,但我无法理解: 1。ChildExpandableListAdapter.java~itemSelected未被调用 public class ChildExpandableListAdapter extends BaseExpandableListAdapter { private Integer

已更新

我想将所选菜单项的背景色更改为淡蓝色。单击时会发生颜色更改,但我仍然无法将上一个菜单项返回到旧颜色(以显示它不再被选中)。下面是我取得的进展,但仍有不足之处

这正是我试图实现的目标,但我无法理解:

1。ChildExpandableListAdapter.java~itemSelected未被调用

public class ChildExpandableListAdapter extends BaseExpandableListAdapter {
    private Integer selectedPosition;

int itemSelected = -1;

public void setSelected(int selected) {
    itemSelected = selected;
}

public void setSelectedPosition (int position) {
    this.selectedPosition = position;
}

@Override
public View getChildView(int groupPosition, int childPosition, final boolean isExpanded, View currentView, ViewGroup parent) {

    if (childPosition == itemSelected) 
        currentView.setBackgroundColor(activity.getResources().getColor(R.color.hpoe_teal));
    else 
        currentView.setBackgroundColor(activity.getResources().getColor(R.color.hpoe_light_light_blue));

}
1。结果

TopicAreaExpandableListAdapter.java~更改每个底部子颜色

@Override
public View getChildView(int groupPosition, int childPosition, final boolean isExpanded, View currentView, ViewGroup parent) {

    if (isExpanded) {
        int color = currentView.getResources().getColor(R.color.hpoe_teal);
        currentView.setBackgroundColor(color);
        currentView.invalidate();
    }
    else {
        int color = currentView.getResources().getColor(R.color.hpoe_light_light_blue);
        currentView.setBackgroundColor(color);
    }
}
2。结果