1

There is an EditText, what I want is when I select it ,I should get the cursor position. The maximum length of the edittext is 13.

Also in my edittext, the first three character's type is text and the other character's type is number. If the first three characters are selected, the input type of keyboard should show text. And if any other characters are selected ,then the input type should be number. How to do this?

6
  • 1
    What did you try so far? Share your efforts Commented Jul 13, 2018 at 6:44
  • 1
    I tried but I don't want to do this. Did you understand question? Commented Jul 13, 2018 at 6:50
  • 1
    @InsaneCat it is not duplicate at all. Read question again. Commented Jul 13, 2018 at 6:54
  • You need to set EditText inputType based on what user is typing? Commented Jul 13, 2018 at 7:03
  • Yes, I need to set EditText inputType based. But the first three character's type is text and the other character's type is number Commented Jul 13, 2018 at 7:15

1 Answer 1

1

I think this code can help you ❤ :

Class Code :

edittext = (EditText) findViewById(R.id.edtxt); edittext.setInputType(InputType.TYPE_CLASS_TEXT); edittext.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(final CharSequence s, int start, int before, int count) { if (edittext.getText().length() < 3 ) { edittext.setInputType(InputType.TYPE_CLASS_TEXT); } else if (edittext.getText().length() == 3 ) { edittext.setInputType(InputType.TYPE_CLASS_NUMBER); }} @Override public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } });}} 

Xml Code :

<EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:maxLength="13" android:id="@+id/edtxt" android:ems="10"/> 
Sign up to request clarification or add additional context in comments.

1 Comment

I used addTextChangedListener but I did another with way

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.