【发布时间】:2020-01-02 17:31:15
【问题描述】:
当我尝试将适配器设置为我的 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)
这就是我在构建时得到的:
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)fu** * 向上 Kotlin 绑定 -
确实是 Kotlin
-
...所以你试过直接使用setter吗?
-
kotlin 设置适配器的方式不适用于自定义适配器。只是WTF
标签: android kotlin android-listview expandablelistview listadapter