Search code examples
androidandroid-edittextandroid-textinputlayoutinput-mask

Edittext - Mask with date format


enter image description here

I use redMadRobot/input-mask library to mask edittext. But I need space between DD / MM / YYYY like in example image and / symbol must be always visible. But I can't do it with this library as I see.

Code :

const val DATE_MASK = "[00]{/}[00]{/}[9900]"

MaskedTextChangedListener.Companion.installOn(
            editText, DATE_MASK, object : MaskedTextChangedListener.ValueListener {
                override fun onTextChanged(
                    maskFilled: Boolean,
                    extractedValue: String,
                    formattedValue: String
                ) {
                    //transactions
                }
            }
        )

Is there any native edittext property to make this desgin or can you suggest another library?


Solution

  • Library author here.
    input-mask-android is about text formatting, but your question looks more layout-related.

    Three EditText components plus two / labels between them might do the trick. setOnEditorActionListener and TextWatcher listeners will help with cursor movement.

    Or you could just put a couple of spaces within curly brackets and call it a day: [00]{ / }[00]{ / }[9900]

    I'd also suggest reading more about our affine masks, and then use a couple of patterns for the sake of year correctness:

    • [00]{ / }[00]{ / }[00]
    • [00]{ / }[00]{ / }[0000]