美文网首页安卓开发
使用kotlin自定义dialog详解

使用kotlin自定义dialog详解

作者: 夜封雪_2696 | 来源:发表于2020-04-10 15:57 被阅读0次

```

/**

*  author:CQ

*  Date:2020-04-09

*  Description:调拨出入库类型选择弹出框

*/

class AllotTypeDialog : Dialog {

    private var cox: Context? =null

    private var allotTitle: TextView? =null// 标题

    private var allotRecyclerView: RecyclerView? =null // 列表

    private var allotSure: TextView? =null // 确定按钮

    private var allotTypeDialogAdapter: AllotTypeDialogAdapter? =null // 适配器

    private var list: MutableList? =null// list

    private var onSelectTypeListener: OnSelectTypeListener? =null // 选择类型监听

    private var selectIn: String =""

    public fun SetOnSelectTypeListener(onSelectTypeListener: OnSelectTypeListener) {

        this.onSelectTypeListener = onSelectTypeListener

    }

    constructor(context: Context) :super(context) {

            cox = context

            initView()

        }

      constructor(context: Context, themeStyle: Int, select: String) :super(context, themeStyle) {

            cox = context

            this.selectIn = select

            initView()

    }

    private fun initView() {

list =mutableListOf()

onInitData()

}

private fun onInitData() {

val selectList =selectIn.split(",")

list!!.run {

            add(AllotTypeBean(0, "全部", selectList.size ==9))

add(AllotTypeBean(1, "渠道调拨", selectList.contains("1")))

add(AllotTypeBean(2, "渠道调退", selectList.contains("2")))

add(AllotTypeBean(3, "店铺配货", selectList.contains("3")))

add(AllotTypeBean(4, "店铺配退", selectList.contains("4")))

add(AllotTypeBean(5, "批发销货", selectList.contains("5")))

add(AllotTypeBean(6, "批发退货", selectList.contains("6")))

add(AllotTypeBean(9, "仓库移仓", selectList.contains("9")))

add(AllotTypeBean(10, "门店横调", selectList.contains("10")))

add(AllotTypeBean(30, "越级调拨", selectList.contains("30")))

}

    }

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

var dialogWindow =window

        dialogWindow.setGravity(Gravity.CENTER)

setContentView(R.layout.dialog_allot_type)

allotTitle = findViewById(R.id.dialog_allot_type_title)

allotRecyclerView = findViewById(R.id.dialog_allot_type_recycleView)

allotSure = findViewById(R.id.dialog_allot_type_sure)

allotSure!!.setOnClickListener{

            var select =""

            for (iin 1 until list!!.size) {

if (list!![i].isCheck)

select +="${list!![i].type},"

            }

if (select =="") {

(cox as AllotAbsActivity).toastMsg("请选择类型")

}else {

select = select.substring(0, select.length -1)

if (onSelectTypeListener !=null) {

onSelectTypeListener!!.onSelect(select)

}

dismiss()

}

}

        allotTypeDialogAdapter = AllotTypeDialogAdapter(cox!!, list!!)

allotRecyclerView!!.layoutManager = LinearLayoutManager(cox)

allotRecyclerView!!.adapter =allotTypeDialogAdapter

        allotTypeDialogAdapter!!.setOnClickItemListener(object : AllotTypeDialogAdapter.OnClickItemListener {

override fun onClickItem(position: Int) {

if (position ==0) {

list!![0].isCheck = !list!![0].isCheck

                    for (iin 1 until list!!.size) {

list!![i].isCheck =list!![0].isCheck

                    }

}else {

list!![position].isCheck = !list!![position].isCheck

                    var selectAll =true

                    for (iin 1 until list!!.size) {

if (!list!![i].isCheck)

selectAll =false

                    }

list!![0].isCheck = selectAll

}

allotTypeDialogAdapter!!.setOnRefresh(list!!)

}

})

var windowManager = (cox as Activity).windowManager

        var display = windowManager.defaultDisplay

        var lp =window.attributes

        lp.width = display.width *4 /5

        window.attributes = lp

setCanceledOnTouchOutside(true)

}

/**

* 获取显示类型

*/

    public fun getTypeShow(): String {

var show =""

        for (iin 1 until list!!.size) {

if (list!![i].isCheck)

show +="${list!![i].name},"

        }

if (show =="")

return show

return show.substring(0, show.length -1)

}

public interface OnSelectTypeListener {

fun onSelect(select: String)

}

}

相关文章

  • 使用kotlin自定义dialog详解

    ``` /** * author:CQ * Date:2020-04-09 * Description:调拨出入库...

  • Dialog

    安卓dialog的使用+如何自定义dialog自定义Dialog自定义Dialog 自定义

  • android dialog

    参考于:Android之Dialog详解 7种形式的Android Dialog使用举例 (一)概述 andro...

  • 自定义dialog中使用scrollview包裹TextView

    dialog中使用scrollview包裹TextView,导致Textview显示不全 今天在自定义dialog...

  • Dialog使用详解

    我们使用Dialog来实现中间弹框和底部弹框两种效果 第一种:底部弹框效果如下图: 1、定义DemoDialog,...

  • 自定义分享dialog

    自定义dialog布局 布局内容adapter 设置圆角 自定义圆角view 使用 自定义属性

  • Flutter - 自定义Dialog

    Flutter - 自定义Dialog 开发中,我们经常需要向用户展示信息,多数情况下,我们使用dialog展示提...

  • 移动端dialog组件

    移动端dialog组件 dialogView是满足移动端下,用户自定义的dialog组件,API可扩展性强,使用便...

  • Notification详解

    Notification详解 Notification的使用步骤 自定义Notification样式 自定义Not...

  • 自定义Dialog

    自定义Dialog的主题 自定义Dialog的布局文件 继承Dialog 并在onCreate方法中将布局设置给D...

网友评论

    本文标题:使用kotlin自定义dialog详解

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