Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. class MainActivity : AppCompatActivity() {
  2.  
  3. private var isButtonClickProcessing = false
  4.  
  5. @SuppressLint("CheckResult")
  6. override fun onCreate(savedInstanceState: Bundle?) {
  7. super.onCreate(savedInstanceState)
  8. setContentView(R.layout.activity_main)
  9.  
  10. val nicknameInputField = findViewById<EditText>(R.id.nicknameInputField)
  11. val passwordInputField = findViewById<EditText>(R.id.passwordInputField)
  12. val okButton = findViewById<Button>(R.id.okButton)
  13.  
  14. nicknameInputField.addTextChangedListener(object : TextWatcher {
  15. override fun afterTextChanged(p0: Editable?) {
  16. }
  17.  
  18. override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
  19. }
  20.  
  21. override fun onTextChanged(text: CharSequence?, p1: Int, p2: Int, p3: Int) {
  22. text?.let { // 입력 내용에 따라 버튼색 변하게 하기
  23. if (text.length >= 4 && passwordInputField.length() >= 4) {
  24. okButton.setBackgroundColor(Color.BLUE)
  25. } else {
  26. okButton.setBackgroundColor(Color.GRAY)
  27. }
  28. }
  29. }
  30. })
  31.  
  32. passwordInputField.addTextChangedListener(object : TextWatcher {
  33. override fun afterTextChanged(p0: Editable?) {
  34. }
  35.  
  36. override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
  37. }
  38.  
  39. override fun onTextChanged(text: CharSequence?, p1: Int, p2: Int, p3: Int) {
  40. text?.let { // 입력 내용에 따라 버튼색 변하게 하기
  41. if (text.length >= 4 && nicknameInputField.length() >= 4) {
  42. okButton.setBackgroundColor(Color.BLUE)
  43. } else {
  44. okButton.setBackgroundColor(Color.GRAY)
  45. }
  46. }
  47. }
  48. })
  49.  
  50. okButton.setOnClickListener {
  51. // 버튼 클릭에 쿨타임 걸기
  52. if(isButtonClickProcessing) return@setOnClickListener
  53. isButtonClickProcessing = true
  54. Observable.timer(1, TimeUnit.SECONDS).subscribe { isButtonClickProcessing = false }
  55.  
  56. when {
  57. nicknameInputField.length() < 4 -> Toast.makeText(this, "닉네임 4글자 이상!", Toast.LENGTH_SHORT).show()
  58. passwordInputField.length() < 4 -> Toast.makeText(this, "패스워드 4글자 이상!", Toast.LENGTH_SHORT).show()
  59. else -> {
  60. nicknameInputField.setText("")
  61. passwordInputField.setText("")
  62. Toast.makeText(this, "OK!", Toast.LENGTH_SHORT).show()
  63. }
  64. }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement