Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Adapter to ExpendableListView type mismatch

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;
    }
like image 720
King Bufo Avatar asked Aug 29 '19 12:08

King Bufo


1 Answers

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))
like image 198
Auc Avatar answered Nov 07 '22 00:11

Auc