EditText set max length programmatically | Android Kotlin

EditText set max length programmatically | Android Kotlin - Hello friend inabnomaniiyaha, In the article that you read this time with the title EditText set max length programmatically | Android Kotlin, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel kotlin,what we write you can understand. Alright, happy reading.

Judul : EditText set max length programmatically | Android Kotlin
link : EditText set max length programmatically | Android Kotlin

Baca juga


EditText set max length programmatically | Android Kotlin

 EditText set max length programmatically

MainActivity.kt

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)


        // set edit text max length to 5 programmatically

        editText.setMaxLength(5)

    }

}



// extension function to set edit text maximum length

fun EditText.setMaxLength(maxLength: Int){

    filters = arrayOf<InputFilter>(LengthFilter(maxLength))

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/constraintLayout"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="#FEFEFA"

    tools:context=".MainActivity">


    <EditText

        android:id="@+id/editText"

        android:layout_width="0dp"

        android:layout_height="wrap_content"

        android:layout_marginStart="12dp"

        android:layout_marginEnd="12dp"

        android:inputType="text|textVisiblePassword"

        android:padding="12dp"

        app:layout_constraintBottom_toBottomOf="parent"

        app:layout_constraintEnd_toEndOf="parent"

        app:layout_constraintStart_toStartOf="parent"

        app:layout_constraintTop_toTopOf="parent"

        app:layout_constraintVertical_bias="0.12" />

 

EditText set max length programmatically


</androidx.constraintlayout.widget.ConstraintLayout>




That's the article EditText set max length programmatically | Android Kotlin

That's it for the article EditText set max length programmatically | Android Kotlin this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the article EditText set max length programmatically | Android Kotlin with link addresshttps://inabnonapudyawanabing.blogspot.com/2020/09/edittext-set-max-length.html

0 Response to " EditText set max length programmatically | Android Kotlin"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...