当我尝试将适配器设置为我的ExpendableListView时,它期望使用ListAdapter,但我想使用一个自定义的ExpandableListAdapter来扩展BaseExpandableListAdapter。
这是我的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>
设置适配器:
exp_lv_nav.adapter = ExpandableListAdapter(this, listDataHeader, listDataChild, exp_lv_nav)
构建时我得到了以下内容:
Error : Type mismatch: inferred type is ExpandableListAdapter but ListAdapter! was expected
我的适配器顶部:
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;
}
exp_lv_nav.adapter = ExpandableListAdapter(this, listDataHeader, listDataChild, exp_lv_nav)
这看起来不像是Java
... 如果是 Kotlin ... 那么...setAdapter(ListAdapter adapter)
和setAdapter(ExpandableListAdapter adapter)
搞砸了 Kotlin 绑定。 - Selvin