我理解的是expandablelistview分为六个部分:activity,activity.xml,group.xml,item.xml,adapter,实体类;
activity是程序的活动部分;
activity.xml是对应活动的界面,本demo写了一个expandablelistview;
group.xml是程序界面的group部分布局;
item.xml是程序的item部分界面布局;
adapter是适配器;
实体类是传进去的参数(本demo中放到了MainActivity.java中的list_group和list_item中)。
下面是具体的程序:
1.MainActivity.java
package com.example.expandablelistview; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ExpandableListView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { List<String> list_group = new ArrayList<>(); List<List<String>> list_item = new ArrayList<>(); ExpandableListView expandableListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initData(); expandableListView = findViewById(R.id.exp_id); Expandable_Adapter adapter = new Expandable_Adapter(list_group,list_item); expandableListView.setAdapter(adapter); expandableListView.setOnItemLongClickListener(onItemLongClickListener); } private AdapterView.OnItemLongClickListener onIt