我正在尝试使用Kotlin在Android Studio内部动态填充可扩展列表 View 。但是到目前为止,我还无法找到任何最新的函数来执行此操作,我发现的所有函数似乎都已过时。这是我的基本代码:
private val shows = listOf("First", "Breaking Bad", "Game of Thrones", "Bob and Martin...")
private val expandableListView: ExpandableListView by bind(R.id.theListView)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Add items to expandable list view here
}
提前致谢
最佳答案
对我来说,它工作正常。
在定义 list 数据的 Activity 中,执行以下操作:
private ArrayList<HeaderInfo> SectionList = new ArrayList<>();
...
//create the adapter by passing your ArrayList data
listAdapter = new ExpandableListAdapter(MyListActivity.this, SectionList);
//attach the adapter to the list
expandableListView.setAdapter(listAdapter);
这是我的可扩展列表适配器中的构造函数
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<HeaderInfo> SectionList;
public ExpandableListAdapter(Context context, ArrayList<HeaderInfo>
SectionList) {
this.context = context;
this.SectionList = SectionList;
}
...