2017-06-19 14 views
5

Próbuję dynamicznie wypełniać mój widok listy rozwijanej wewnątrz Android Studio za pomocą Kotlin. Ale od tej chwili nie byłem w stanie znaleźć żadnej aktualnej funkcji, która by to zrobiła, wszystkie funkcje, które znalazłem, wydają się przestarzałe. To jest mój kod szkielet:Kotlin - Dodaj pozycje do ExpandableListView

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 
    } 

góry dzięki

+1

Google „ExpandableListView przykładem” i powinieneś być w stanie zrozumieć. – rozina

+0

Tak, znalazłem funkcję setAdapter. Wydaje się, że tylko trudniej jest stworzyć adapter ExpandableListAdapter. Udało mi się tylko uruchomić ArrayAdapter, co nie pomaga mi zbytnio. – OhMad

Odpowiedz

0

Dla mnie to działało dobrze.
W swojej działalności, w których można zdefiniować swoje listData to zrobić:

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); 

Jest to konstruktor w moim rozwijaną listą adaptera

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; 
} 
...