java—在kotlin中的同一个活动内以数字方式传递数据

iyr7buue  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(213)

我有一个弹出式布局与2编辑文本字段。我在我的活动中这样叫按钮点击

private fun setDataInLayout() {

        val view = LayoutInflater.from(this).inflate(R.layout.popup_add_mass_and_value, null)
        val mBuilder = AlertDialog.Builder(this).setView(view)
        val mAlertDialog = mBuilder.show()
        mAlertDialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
        view.eMass?.setText(newMass) // set a string to field, but it doesn`t update it
        view.eMass?.setSelection(view.eMass.text.length!!)
        val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)

        // some further code
}

在同样的活动中,我有一个蓝牙音阶码,从中我得到了大量的信息

private val task: Runnable = object : Runnable {
        @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
        override fun run() {
            handler.postDelayed(this, 150)
            if (!scale!!.bleIsEnabled()) {
                return
            }
          if(condition){
           //here I need to set weight from scale to eMass
            newMass=java.lang.String.format("%4.1f",
                scale!!.getDevicelist()!![i].scalevalue)   
           //here I tried to set my string variable                       
           }
}}

我试过两种方法,第一种是直接访问runnable中的emass字段,但我不知道如何正确访问它。第二种方法,我声明了一个字符串newmass,并在runable中正确地设置了它,但是我不能将它传递给emass字段,只有在关闭popup并再次打开它时才会显示值。我做错什么了?有没有其他方法可以在弹出式布局中将质量从我的比例传递到编辑文本字段?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题