Masked Input Using EditText Widget in Android

后端 未结 6 931
花落未央
花落未央 2020-12-01 12:48

Is there a way I can specify an input mask to the EditText control in Android?

I want be able to specify something like ### - ## - #### for a Social Security Number.

6条回答
  •  春和景丽
    2020-12-01 12:58

    Try using an InputFilter rather than an OnKeyListener. This means you don't have worry about tracking individual key presses and it will also handle things like pasting into a field which would be painful to handle with an OnKeyListener.

    You could have a look at the source of the InputFilter implementations that come with Android to give you a starting point for writing your own.

提交回复
热议问题