【问题标题】:How to clear input in edittext with button KOTLIN如何使用 KOTLIN 按钮清除edittext中的输入
【发布时间】:2021-08-02 23:37:51
【问题描述】:

单击按钮时我需要清除editText。在 java 中我们使用 getText 或 setText 但在 kotlin 中我找不到任何东西。

    val email=findViewById<EditText>(R.id.email).apply {
        text= ""
    }

我尝试使用它,但 ---text=""--- 给我一个类型不匹配

【问题讨论】:

    标签: android kotlin button android-edittext


    【解决方案1】:

    首先,您还需要获取按钮 ID。然后你应该在你的按钮上设置 setOnClickListener 并清除 EditText 操作。

    val button = findViewById<Button>(R.id.button)
    val emailEditText = findViewById<EditText>(R.id.email)
    button.setOnClickListener { emailEditText.setText("") }
    

    【讨论】:

      猜你喜欢
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      • 2018-09-17
      • 2014-05-28
      • 1970-01-01
      • 2017-11-29
      相关资源
      最近更新 更多