Setting Adapter to ExpendableListView type mismatch
Asked Answered
S

1

8

When i try to set the adapter to my ExpendableListView it expects ListAdapter but i want to use a custom ExpandableListAdapter which extends BaseExpandableListAdapter

This is my ExpandableListView:

<ExpandableListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:layout_marginTop="160dp"
    android:id="@+id/exp_lv_nav">
</ExpandableListView>

Setting the adapter:

exp_lv_nav.adapter = ExpandableListAdapter(this, listDataHeader, listDataChild, exp_lv_nav)

And this is what I get when building:

Error : Type mismatch: inferred type is ExpandableListAdapter but ListAdapter! was expected

Top of my adapter:

public class ExpandableListAdapter extends BaseExpandableListAdapter {
    private Context mContext;
    private List<ExpandedMenuModel> mListDataHeader; 

    private HashMap<ExpandedMenuModel, List<String>> mListDataChild;
    ExpandableListView expandList;

    public ExpandableListAdapter(Context context, List<ExpandedMenuModel> listDataHeader, HashMap<ExpandedMenuModel, List<String>> listChildData, ExpandableListView mView) {
        this.mContext = context;
        this.mListDataHeader = listDataHeader;
        this.mListDataChild = listChildData;
        this.expandList = mView;
    }
Striated answered 29/8, 2019 at 12:25 Comment(4)
exp_lv_nav.adapter = ExpandableListAdapter(this, listDataHeader, listDataChild, exp_lv_nav) hmmm it doesn't looks like java ... and if's it's Kotlin ... then ... well .... setAdapter(ListAdapter adapter) and setAdapter(ExpandableListAdapter adapter) fu*** up Kotlin bindingPoundal
Its Kotlin indeedStriated
... so did you tried to use setter directly?Poundal
The kotlin way to set the adapter dont work with custom adapters. just WTFStriated
T
9

It seems to be a problem in Kotlin. For now, instead of setting the adapter using Kotlin's generated getter/setter as you have in the question:

exp_lv_nav.adapter = ExpandableListAdapter(this, listDataHeader, listDataChild, exp_lv_nav)

replace with:

exp_lv_nav.setAdapter(ExpandableListAdapter(this, listDataHeader, listDataChild, exp_lv_nav))
Talesman answered 4/1, 2020 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.