简体   繁体   English

单击按钮后如何更新 TextView 文本

[英]How to update TextView text after clicking a button

when i cick on number the TextView Doesnt change it supposed to show number when i click on them like the calculator that's my code i still in the first part of the app当我点击数字时,TextView 不会改变它应该显示数字,当我像计算器一样点击它们时,我的代码仍然在应用程序的第一部分

 fun clicknumber(view: View) {

        var buselected = view as Button
        var tvnum = tv.text.toString()
       if (newOp){
            tv.text = ""
       }
        newOp=false


        when (buselected.id) {
           one.id-> tvnum += "1"
            two.id-> tvnum += "2"
            three.id-> tvnum += "3"
            four.id-> tvnum += "4"
            five.id-> tvnum += "5"
            six.id-> tvnum += "6"
            seven.id-> tvnum += "7"
            eight.id-> tvnum += +"8"
            nine.id-> tvnum += "9"
            dot.id-> tvnum += "."
            minusplus.id -> tvnum = "-" + tvnum
        }
    }
}

i think the problem is in the "tvnum" and i wanna to clear the textview when i do a new operation, i write the code but it doesnt work so good我认为问题出在“tvnum”中,我想在执行新操作时清除 textview,我编写了代码,但效果不佳

You're assigning tvnum but you're doing nothing with it.您正在分配tvnum但您什么也没做。 You need to set the text in the TextView instead.您需要改为在 TextView 中设置文本。 tv.text = tvnum

Honestly saying i can't understand your question but still you can try this... Change the text of the view individually in each case.老实说我不明白你的问题,但你仍然可以试试这个......在每种情况下单独更改视图的文本。 like tv.text = "---"像 tv.text = "---"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM