How to get count from edit text while entering int values?

333 Views Asked by At

Actually I have A requirement, where I need to take mobile no from edit text, and as the count is equal to 10 then it must call the Intent. So I am using "addTextChangedListener".

et_mobile_no.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if(count == 10){
                Toast.makeText(getApplicationContext(),
                        "Count is " + count, Toast.LENGTH_SHORT).show();
    }
}

It is working when I am putting characters or string but when I am putting mobile no means int value it is not giving the toast. Please help me how can I get the count while entering mobile no. ????

2

There are 2 best solutions below

0
On

Try using afterTextChanged in the TextWatcher instead.

1
On

Yes it little tricky. I got the answer. Here is answer.

   et_mobile_no.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            if (s.length() == 10) {
                if (et_mobile_no.getText().toString().equals("9920263416")) {

                    Intent i = new Intent(SplashActivity.this,
                            CustomerLookUp.class);
                    startActivity(i);
                } else {
                    hided_views.setVisibility(View.VISIBLE);
                }
            }
        }