Kotlin-指定为非null的参数为null

时间:2019-08-24 07:50:53

标签: android kotlin expandablelistview

我坚持了一天,但没有找到解决方案。 我正在使用自定义Expandable listView AnimatedExpandableListView.AnimatedExpandableListAdapter在我的应用中显示Expandable类型的listView。数据设置在“页眉”部分,但是当我单击“页眉”以打开子菜单(子菜单)时,会出现错误-

  

java.lang.IllegalArgumentException:指定为非null的参数为null:方法kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull,参数convertView

at com.package.supports.AnimatedExpandableListView$AnimatedExpandableListAdapter.getChildView(AnimatedExpandableListView.kt)

我尝试了很多解决方案,但没有任何人工作。

到目前为止,我做到了

 var navigation_menu: AnimatedExpandableListView ?= null
 navigation_menu = findViewById<View>(R.id.navigation_menu) as AnimatedExpandableListView

navigation_menu!!.setOnGroupClickListener { parent, v, groupPosition, id ->
        if (parent.isGroupExpanded(groupPosition)) {
            navigation_menu!!.collapseGroupWithAnimation(groupPosition)
        } else {
            if (groupPosition != previousGroup) {
                parent.collapseGroup(previousGroup)
            }
            previousGroup = groupPosition
            navigation_menu!!.expandGroupWithAnimation(groupPosition)
        }
        parent.smoothScrollToPositionFromTop(groupPosition, 0, 200)
        //parent.smoothScrollToPosition(groupPosition);
        true
    }

将适配器设置为

  

navigation_menu?.setAdapter(NavigationAdapter(context,gp_arr))

在下面的Adapter类getGroupView中

override fun getGroupView(groupPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup): View {

    var convertView = convertView

    val hdr = getGroup(groupPosition) as GP

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.custom_group_item_row, parent, false)
    }

    val txtV = convertView!!.findViewById<View>(R.id.group_name) as TextView
    val arrow = convertView.findViewById<View>(R.id.img_expand) as ImageView
    val viewLine = convertView.findViewById<View>(R.id.viewLine)

    if (isExpanded) {
        arrow.setImageResource(R.drawable.ic_down_arrow)
        viewLine.visibility = View.INVISIBLE
        txtV.setTextColor(ContextCompat.getColor(context, R.color.light_text_color))
    } else {
        viewLine.visibility = View.VISIBLE
        arrow.setImageResource(R.drawable.ic_right_arrow)
        txtV.setTextColor(ContextCompat.getColor(context, R.color.light_text_color))
    }

    txtV.text = hdr.gp_name

    return convertView
}

和getRealChildView如下

override fun getRealChildView(groupPosition: Int, childPosition: Int, isLastChild: Boolean, convertView: View?, parent: ViewGroup): View {

    var convertView = convertView

    val viewHolder: ViewHolder

    val ch_cnt = getChild(groupPosition, childPosition) as NagivationMenu

    val tag = "child"

    if (ch_cnt.tag.equals(tag, ignoreCase = true)) {
        viewHolder = ViewHolder()
        convertView = inflater.inflate(R.layout.custom_child_item_row, null)
        viewHolder.txt_chld = convertView!!.findViewById<View>(R.id.custom_rec_name) as TextView
        viewHolder.chld_cell = convertView.findViewById<View>(R.id.chld_cell) as RelativeLayout
        viewHolder.txt_new = convertView.findViewById<View>(R.id.txt_new) as TextView

        /* if (ch_cnt.getGc_new().equalsIgnoreCase("1")) {
            viewHolder.txt_new.setVisibility(View.VISIBLE);
        } else {
            viewHolder.txt_new.setVisibility(View.GONE);
        }*/

        viewHolder.txt_chld!!.text = ch_cnt.gc_cat_name

        if (!ch_cnt.gc_cat_id.equals("", ignoreCase = true)) {
            viewHolder.chld_cell!!.setOnClickListener {
                cat_id = ch_cnt.gc_cat_id
                getPerspective().navigation_menu!!.collapseGroupWithAnimation(groupPosition)
                getPerspective().img_menu.performClick()
                val isWebGo = ch_cnt.isWebview
                /*if (isWebGo) {
                        getPerspective().showMessage("MOVE TO WEBVIEW");
                    } else {
                        getPerspective().openProdcuctList(cat_id, "home");
                    }*/
                getPerspective().openProdcuctList(cat_id!!, "home")
            }
        }

    } else {
        viewHolder = ViewHolder()
        convertView = inflater.inflate(R.layout.custom_child_header_row, null)
        viewHolder.txt_chld = convertView!!.findViewById<View>(R.id.custom_rec_name) as TextView
        viewHolder.txt_chld!!.text = ch_cnt.gc_cat_name
        viewHolder.txt_chld!!.isClickable = false
    }
    return convertView
}

我是Kotlin的新手,我在Android中执行了相同的代码,并且运行良好。 请帮忙,谢谢。

0 个答案:

没有答案