[JAVA] [Android / Kotlin] UI summary

table of contents

  1. Hide password
  2. Rewrite addTextChangedListener
  3. enum rewrite

1. Hide password

undefined

MainActivity.java


editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);  

activity_main.xml


<EditText
        android:id="@+id/edit_text"
        android:layout_width="200dp"
        android:layout_height="60dp"
        android:inputType="textPassword"></EditText>

2. Rewrite addTextChangedListener

MainActivity.java


  editText.addTextChangedListener(new TextWatcher() { 
       @Override 
       public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
      }
       @Override 
       public void onTextChanged(CharSequence s, int start, int before, int count) { 
         calculatePasswordStrength(s.toString()); 
       } 
       @Override 
       public void afterTextChanged(Editable s) { 
     } 
     }); 
   } 

MainActivity.kt


 edit_text.addTextChangedListener(object : TextWatcher{
            override fun afterTextChanged(p0: Editable?) {
            }

            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }
})

enum rewrite

MainActivity.java


 WEAK(R.string.weak, R.color.weak), 
 MEDIUM(R.string.medium, R.string.medium), 
 STRONG(R.string.strong, R.string.strong),    
 VERY_STRONG(R.string.very_strong, R.string.very_strong); 

MainActivity.kt


WEAK {
        override fun stringId(): Int = R.string.weak
        override fun colorId(): Int = R.color.weak
    },
    MEDIUM {
        override fun stringId(): Int = R.string.medium
        override fun colorId(): Int = R.color.medium
    },
    STRONG {
        override fun stringId(): Int = R.string.strong
        override fun colorId(): Int = R.color.strong
    },
    VERY_STRONG {
        override fun stringId(): Int = R.string.very_strong
        override fun colorId(): Int = R.color.very_strong
    };

    abstract fun stringId(): Int
    abstract fun colorId(): Int

Recommended Posts

[Android / Kotlin] UI summary
Android development link summary
[Android / Kotlin] Detailed notes 2
[Kotlin / Android] Listener rewrite
Android Studio data binding study summary
Summary
[Android] Convert Android Java code to Kotlin
[Kotlin / Android] Create a custom view
Convert all Android apps (Java) to Kotlin
About UI thread processing in Android asynchronous