Check if EditText is empty kotlin android

前端 未结 9 1842
悲哀的现实
悲哀的现实 2020-12-20 12:42

How do you check if an EditText is empty? input type number

\"\"

package com.example.www.myappl         


        
相关标签:
9条回答
  • 2020-12-20 12:46

    try this out:

    bottom.setOnClickListener{
      val new = addText.text.toString()
    
      if (new = isNotEmpty()) {
        //do something
      } else {
        Toast.makeText(context, "Enter some message ", Toast.LENGTH_SHORT).show()
      }
    }
    
    0 讨论(0)
  • 2020-12-20 12:47

    You can be done by below way

    if (mEdtDeviceName.text.toString().trim().isNotEmpty() || 
        mEdtDeviceName.text.toString().trim().isNotBlank()) {
           // your code
    } else {
        Toast.makeText(activity, "Error Msg", Toast.LENGTH_SHORT).show()
    }
    
    0 讨论(0)
  • 2020-12-20 12:51

    Been a new guy Tried lots and this Worked for me

         if(!editTextTerminalName.text.toString().trim().isNotEmpty()) {
    
                    editTextTerminalName?.error = "Required"
    
                }else if(!editTextPassword.text.toString().trim().isNotEmpty()){
    
    
                    editTextPassword?.error = "Required"
                }else{
    
                    avi.visibility= View.VISIBLE // v letter should be capita
    }
    
    0 讨论(0)
  • 2020-12-20 12:54

    Harness Kotlin power by using inline extension functions:

    editText.text.isNotEmpty().apply { 
        //do something
     }
    

    or use let

    0 讨论(0)
  • 2020-12-20 12:57
    class MainActivity : AppCompatActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
    
            val btnSignUp : Button = findViewById(R.id.signUp)
    
            val et_username : EditText = findViewById(R.id.etUsername)
            val et_email : EditText = findViewById(R.id.etEmail)
            val et_password : EditText = findViewById(R.id.etPassword)
    
            btnSignUp.setOnClickListener{
                val user_msg_error: String = et_username.text.toString()
    
                //check if the EditText have values or not
                if(user_msg_error.trim().isEmpty()) {
                    et_username.error = "Required"
                    Toast.makeText(applicationContext, "User Name Required ", Toast.LENGTH_SHORT).show()
                }
                else if (et_email.text.toString().trim().isEmpty()) {
                    et_email.error = "Required"
                    Toast.makeText(applicationContext, "Email Required ", Toast.LENGTH_SHORT).show()
                }
                else if (et_password.text.toString().trim().isEmpty()) {
                    et_password.error = "Required"
                    Toast.makeText(applicationContext, "Password Required ", Toast.LENGTH_SHORT).show()
                }
                else{
                    Toast.makeText(applicationContext, "Login Successful ", Toast.LENGTH_SHORT).show()
    
                // After successful login u will move on next page/ activity
    
                    val i = Intent(this,SecondActivity::class.java)
                    startActivity(i)
                }
    
            }
    
    
        }
    
    
    }
    
    0 讨论(0)
  • 2020-12-20 12:58
    if (regemail.isEmpty())
    {
         Toast.makeText(this,"Enter Email..!!!",Toast.LENGTH_LONG).show()
    }
    
    0 讨论(0)
提交回复
热议问题