我已经解决了这个问题,当我滚动 expandableList 时,我无法更改视图的颜色。我做了两件事。首先是我在活动中添加了这段代码:
expandableList.setOnChildClickListener(new OnChildClickListener(){
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
View view= null ;
//Select's item
select = expandableListInfo[groupPosition].get(childPosition);
//Get the last element visible in expandableList
int lastVis =expandableList.getLastVisiblePosition();
//Get the first element vsible in the expandableList
int firstVis = listadoPedidos.getFirstVisiblePosition();
int count = firstVis;
while (count <= lastVis) {
int viewPosition=count-firstVis;
long longposition = expandableList.getExpandableListPosition(count);
int type = ExpandableListView.getPackedPositionType(longposition);
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPositionLast = ExpandableListView.getPackedPositionGroup(longposition);
//Get the object selected before
//This tag is save in the adapter
Object lastObject = (Object)parent.getTag(R.id.tag_select);
view =(View) parent.getChildAt(viewPosition);
Object ob=view.getTag(R.id.tag_select);
if(ob.equals(lastObject)){
//Change colour view
}
}
count++;
}
...
parent.setTag(R.id.tag_select, select);
return false;
}
});
第二件事是在适配器中添加 getChildView 下一个代码:
convertView.setTag(R.id.tag_select, object);
if(parent.getTag(R.id.tag_select).equals.object){
//// TODO
}