0

how do you get it so that edit text only accepts text if the user had puttet a K in to start with like

  1. KV1096
  2. K0024

1 Answer 1

1

In android, there is a listener for text change:

EditText mEditText = (EditText) findViewById(R.id.my_edit_text); //now you can add the listener here: mEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // here get the value entered by user and get the character //at index 0; String value = "what the user has entered".charAt(0) //now use an if statement here to see if it is your required value (K); if not, set EditText to disabled - not active; } @Override public void afterTextChanged(Editable s) { } }); 

I hope this helps you get started!

Sign up to request clarification or add additional context in comments.

2 Comments

doesn't String value = "what the user has entered".charAt(0) have to be a char instead of string? as it says is incompatible types
Sure you can make it a char

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.