本文环境
Windows10 专业版
Android Studio @ 3.5
SDK @ 29
效果图
二级列表效果图.gif
Demo地址: https://github.com/kangbogg/MultilevelList
布局文件
activity_main.xml
layout/level_1_list_layout.xml
level_2_list_layout.xml
Java代码
MainActivity
package com.example.day0927;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private ExpandableListView elv;
private MyExpandableListAdapter myExpandableListAdapter;
//数据
String[] group = {"张学友", "张国荣"};
String[][] child = {
{"饿狼传说", "遥远的她"},
{"风继续吹", "春夏秋冬"}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
listener();
}
private void initView() {
elv = findViewById(R.id.elv);
myExpandableListAdapter = new MyExpandableListAdapter(group, child, this);
elv.setAdapter(myExpandableListAda