[当我尝试将适配器设置为ExpendableListView时,它期望使用ListAdapter,但是我想使用扩展BaseExpandableListAdapter的自定义ExpandableListAdapter
这是我的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)
错误:类型不匹配:推断的类型为ExpandableListAdapter,但ListAdapter!预计
我的适配器顶部:
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;
}
在科特林,这似乎是一个问题。现在,不用像问题中那样使用Kotlin的生成的getter / setter来设置适配器:
exp_lv_nav.adapter = ExpandableListAdapter(this, listDataHeader, listDataChild, exp_lv_nav)
替换为:
exp_lv_nav.setAdapter(ExpandableListAdapter(this, listDataHeader, listDataChild, exp_lv_nav))