开发者

EditText input with pattern android

开发者 https://www.devze.com 2023-01-26 20:44 出处:网络
I am having a 开发者_运维知识库EditText in which I have to accept alphanumeric input from user which is specific to pattern, and hyphens \'-\' are inserted automatically.

I am having a 开发者_运维知识库EditText in which I have to accept alphanumeric input from user which is specific to pattern, and hyphens '-' are inserted automatically.

"XXX-XXX-XXXX"

how to achieve that ? Is there any pattern tool in android ?


You can achieve that with PatternedTextWatcher.

Edit:

EditText editText = (EditText) findViewById(R.id.edittext);

// Add text changed listener for automatic dots insertion.
editText.addTextChangedListener(new PatternedTextWatcher("###-###-####"));

And in XML:

<EditText
    android:id="@+id/edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:digits="1234567890-"/>


You can use addTextChangedListener to EditText
Refer this question , which demonstrate it

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号