fragment textWatcher的设置位置

override fun onStart() {
        super.onStart()
        Log.d("------------", "1")
        val titleWatcher = object : TextWatcher {
            //使用匿名内部类构建一个监听器监听title文本变化
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                crime.title = s.toString()
            }

            override fun afterTextChanged(s: Editable?) {
            }
        }
        binding.crimeTitle.addTextChangedListener(titleWatcher)//把crimeTitle的文本监听器设置为titleWatcher
        //在onStart里设置监听器防止因fragment状态恢复而触发
        binding.crimeSolved.setOnCheckedChangeListener { _, isChecked ->
            crime.isSolved = isChecked                         //设置checkBox的监听器事件
        }

 

posted @ 2021-05-28 09:06  ou尼酱~~~  阅读(102)  评论(0)    收藏  举报