I am trying to dynamically populate my expandable list view inside of Android Studio using Kotlin. But as of now, I wasn't able to find any up to date function to do so, all functions I found seem to be outdated. This is my skeleton code:
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
}
Thanks in advance
For me it worked fine.
In your activity where you define your listdata do this:
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);
This is the constructor in my expandable list adapter
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;
}
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.