0

When I click the button sub the text inside the editText field should be stored as a string in str. And I need to make sure that the text consists of only alphabets. I'm kinda beginner so I don't have much of an experience.

    final Button sub = findViewById(R.id.submit);
    final EditText name  = findViewById(R.id.name);
    chk.setEnabled(false);
    sub.setOnClickListener(
            new View.OnClickListener()
            {
                public void onClick(View view)
                {
                    str  = name.getText().toString();
                    x = str.length();
                    if (x>=4 || x<=10)
                        chk.setEnabled(true);
                }
            });
Shantanu
  • 43
  • 1
  • 4

1 Answers1

0

You Have to try some code and ask if some error is occurred. StckOverflow is palace to clarify technical doubts .not a place to ask for opinion. Try to change your questioning pattern.

You have to use TextWatcher() for achieve this.

Refer the Below Links:

TexWatcher fo Android

TextChangerListener Android

You can use TextWatcher for your edittext,

eg:

 editText.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) {
                 //Do the validation here by checking last entered character is alphabet with string matching or by using ASCII values. 

            }

            @Override
            public void afterTextChanged(Editable s) {

                    //Do the validation and further coding.

            }
Tomin B Azhakathu
  • 2,656
  • 1
  • 19
  • 28