0

I am creating a application where I have EditText where user can Enter Url's or normal text so I want that if in EditText any URL contains I want to perform some operations

here is example what kind of text can be in EditText -

hello you can check this https://stackoverflow.com
//this type of text can be entered by the user so how can I detect

Any help will be Appreciated.

I've Tried this but not working -

binding.editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.toString().contains(Patterns.WEB_URL.toString())) {
                Toast.makeText(this, "Yes url is available", Toast.LENGTH_SHORT).show();
            } else {

       Toast.makeText(this, "url is not available", 
Toast.LENGTH_SHORT).show();

            }
        }
    });

0 Answers0