Skip to content

Instantly share code, notes, and snippets.

@theerasan
Last active July 10, 2017 18:45
Show Gist options
  • Select an option

  • Save theerasan/183279ddf01aee2ff8f3b536484a6790 to your computer and use it in GitHub Desktop.

Select an option

Save theerasan/183279ddf01aee2ff8f3b536484a6790 to your computer and use it in GitHub Desktop.
private var emailField: AutoCompleteTextView? = null
private var passwordField: EditText? = null
private var signInButton: Button? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
emailField = findViewById(R.id.email) as AutoCompleteTextView
passwordField = findViewById(R.id.password) as EditText
signInButton = findViewById(R.id.email_sign_in_button) as Button
val textWatcher = object:TextWatcher {
override fun afterTextChanged(s: Editable?) { }
override fun beforeTextChanged(s: CharSequence?,
start: Int,
count: Int,
after: Int) { }
override fun onTextChanged(s: CharSequence?,
start: Int,
before: Int,
count: Int) {
checkIsReadyToSignIn()
}
}
emailField!!.addTextChangedListener(textWatcher)
passwordField!!.addTextChangedListener(textWatcher)
signInButton!!.setOnClickListener { performLogin() }
signInButton!!.isEnabled = false
}
private fun performLogin() {
val stringToShow = emailField?.text.toString()
+ " "
+ passwordField?.text.toString()
Toast.makeText(this, stringToShow, Toast.LENGTH_LONG).show()
emailField?.setText("")
passwordField?.setText("")
}
private fun checkIsReadyToSignIn() {
val notEmptyStrings = TextHelper.isNotEmptyStrings(emailField!!.text.toString(),
passwordField!!.text.toString())
signInButton!!.isEnabled = notEmptyStrings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment