Android expandablelistview用于展开/折叠的不同样式

Android expandablelistview用于展开/折叠的不同样式,android,expandablelistview,Android,Expandablelistview,我正在尝试获得一个自定义的Expandablelistview,它在展开/折叠状态下具有不同的布局 适配器 @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { String headerTitle = ((User) getGroup(groupPosition)).getName(); if (convertView =

我正在尝试获得一个自定义的Expandablelistview,它在展开/折叠状态下具有不同的布局

适配器

@Override

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

String headerTitle = ((User) getGroup(groupPosition)).getName();
if (convertView == null) {
    LayoutInflater infalInflater = (LayoutInflater) this.con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if(isExpanded) {
        Log.e("DBG", "isExpanded");
        convertView = infalInflater.inflate(R.layout.expanablelistview_header_expanded, parent, false);
    } else {
        Log.e("DBG", "isNotExpanded");
        convertView = infalInflater.inflate(R.layout.expanablelistview_header_collapse, parent, false);
    }
}

TextView lblListHeader = (TextView) convertView.findViewById(R.id.tv_user);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);

return convertView;
}
expanablelistview\u header\u collapse.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/transparent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/xml_border"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tv_user"
            android:textSize="20sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <View 
        android:background="@color/transparent"
        android:layout_width="match_parent" 
        android:layout_height="10dp" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/xml_border_top"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv_user"
        android:textSize="20sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

expanablelistview\u header\u expanded.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/transparent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/xml_border"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tv_user"
            android:textSize="20sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <View 
        android:background="@color/transparent"
        android:layout_width="match_parent" 
        android:layout_height="10dp" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/xml_border_top"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv_user"
        android:textSize="20sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

这是我的尝试,但此方法仅在开始时调用,而不是在扩展状态更改时调用

谢谢你的想法

问题在于

if (convertView == null)

谢谢大家!

尝试在中的MainActivity中加载布局

<ExpandableListView Obj>.setOnGroupExpandListener();
.setOnGroupExpandListener();

.setOnGroupCollapseListener();

这两个布局都包含什么布局?您可以隐藏和显示“视图”,并更改线性布局的背景。或者将if-else条件置于if条件之外。会的work@SurenderKumar非常感谢。但是我会做更多的改变,但是这个;)这真的是最有用的方法吗?奥特赛德在哪里?