美文网首页
在kotlin中 重写BaseExpandableListAda

在kotlin中 重写BaseExpandableListAda

作者: 凹凸大帝 | 来源:发表于2019-12-13 16:43 被阅读0次

使用ExpandableListView时,先写的是java的代码,继承BaseExpandableListAdapter,然后转kotlin,运行起来一直报错:

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView

        at com.jjhd.wash.adapter.BillListAdapter.getGroupView(BillListAdapter.kt)

        at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)

后来研究了很久,才发现是变量非空的问题

java代码转kotlin时,

override fun getGroupView(

groupPosition: Int,

isExpanded: Boolean,

convertView: View,

parent: ViewGroup

): View {

return LayoutInflater.from(context).inflate(R.layout.item_bill_list_group,null)

}

参数中,convertView是可以为空的,kotlin在检测非空时就报错了

把convertView:View改为covnertView:View?就搞定了。

getChildView时同理

相关文章

网友评论

      本文标题:在kotlin中 重写BaseExpandableListAda

      本文链接:https://www.haomeiwen.com/subject/vtafnctx.html