我有一个可扩展的 ListView ,我想在单击父组并显示子组时将图标从向右箭头更改为向下箭头。目前,当我单击父组展开并显示子组时,图标不会从右箭头更改为向下箭头,它只是保留为右箭头图标。这就是我现在的可扩展适配器中的内容。
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = getGroup(groupPosition).toString();
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
ImageView arrowImageView = (ImageView) convertView.findViewById (R.id.group_header_arrow);
if (isExpanded) {
arrowImageView.setImageResource(R.drawable.arrow_down);
(ApplicationContext.Activity.Resources.GetColor (Resource.Color.standard_blue));
}
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setText(headerTitle);
TextView Header = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setText(headerTitle);
return convertView;
}
组 header 的 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#f4f4f4">
<ImageView
android:id="@+id/group_header_arrow"
android:src="@drawable/arrow_right"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp" />
<TextView
android:id="@+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="17dp"
android:textColor="#388C2A" />
</LinearLayout>
最佳答案
在适配器类中添加此代码,
final ExpandableListView mExpandableListView= (ExpandableListView) parent ;
mExpandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
arrowImageView.setImageResource(R.drawable.arrow_down);
}
});
mExpandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
arrowImageView.setImageResource(R.drawable.arrow_left);
}
});
if(mExpandableListView.isGroupExpanded(groupPosition))
{
arrowImageView.setImageResource(R.drawable.arrow_down);
}
else
{
arrowImageView.setImageResource(R.drawable.arrow_left);
}
关于java - 当父组已展开以显示其子组时,如何更改图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42199704/