我正在尝试使用Kotlin在Android Studio中动态填充我的可扩展列表视图.但截至目前,我无法找到任何最新功能,我找到的所有功能似乎都已过时.这是我的骨架代码:
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
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
对我来说效果很好。
在定义列表数据的活动中执行以下操作:
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);
Run Code Online (Sandbox Code Playgroud)
这是我的可扩展列表适配器中的构造函数
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;
}
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1730 次 |
| 最近记录: |