美文网首页Android开发
Android开发列表弹框

Android开发列表弹框

作者: 你的益达233 | 来源:发表于2020-12-12 17:41 被阅读0次

    效果图:

    列表弹框.png

    二、思路

    列表数据不定,所以采用RecyclerView,创建个回调点击的position位置,处理相应事件即可

    二、关键代码

    fun showSelectDialog(context: Context,items:MutableList<String>,selectItemListener: SelectItemListener?){
        var dialog = getCancelDialog(context)
        dialog.show()
        val window = dialog.window
        window.setGravity(Gravity.BOTTOM)
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        window.setContentView(R.layout.dialog_items)
    
        val rv = window.findViewById<RecyclerView>(R.id.rv_items)
        rv.layoutManager = LinearLayoutManager(context)
    
        val adapter = DialogSelectItemAdapter(data = items)
        rv.adapter = adapter
    
        adapter.setOnItemClickListener { adapter, view, position ->
            selectItemListener?.clickPosition(position)
            dialog.dismiss()
        }
    
        val tv_cancel = window.findViewById<TextView>(R.id.tv_cancel)
        tv_cancel.setOnClickListener {
            dialog.dismiss()
        }
    }
    
    interface SelectItemListener{
        fun clickPosition(position:Int)
    }

    相关文章

      网友评论

        本文标题:Android开发列表弹框

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