@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inf.inflate(R.layout.list_group, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.lblListHeader);
convertView.setTag(holder);
} } else {
holder = (ViewHolder) convertView.getTag();
}
ImageView imageView = (ImageView) convertView.findViewById(R.id.indicator);
if(isExpanded){
imageView.setImageResource(R.drawable.arrowup);
} } else {
imageView.setImageResource(R.drawable.arrowdown);
}
holder.text.setText(getGroup(groupPosition).toString());
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
private class ViewHolder {
TextView text;
}
}
}
I implemented an expandable list view in one fragment. I want to put the arrowup icon when the list view opens, and arrowdown when it closes.
ImageView imageView = (ImageView) convertView.findViewById(R.id.indicator);
if(isExpanded){
imageView.setImageResource(R.drawable.arrowup);
} } else {
imageView.setImageResource(R.drawable.arrowdown);
}
I think this is the problem. How should I put it in?ㅜ??
android listview
The reason why the image does not change when you click or expand/Collapse GroupView() function calls. The isExpanded
value within getGroupView() is only the status value at the time it was drawn on the screen because this function is called when the group view is displayed on the screen.
In summary, when you click the group view or run the expandGroup()/collapseGroup() function, getGroupView() is not called back, so the image does not change. Use the listener below to apply the image change code.
© 2024 OneMinuteCode. All rights reserved.