skip to Main Content

I want the edittext value without clicking any button.I want to enter something in edittext and after entering the value want to get the value and start a method.

2

Answers


  1. you can use some listener for Edittext in android an watch all changes inside an edittext every time user type a new character in Edittext this listener invoked

    here is my sample code in Kotlin:

     search_EditText.addTextChangedListener(object : TextWatcher {
            override fun afterTextChanged(s: Editable) {
               // Do something
                }
            override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
              // Do something
            }
    
            override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
                if (s.length != 0) {
                    // Do something
                } else {
                      // Do something
                }
            }
        })
    
    Login or Signup to reply.
  2. You can use TextWatcher like this.

    TextWatcher textWatcher = 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) {
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    Toast.makeText(AccountSettingsActivity.this, "New text is: " + s.toString(), Toast.LENGTH_SHORT).show();
                }
            };
    

    And you can assing the TextWatcer in your EditText like this

    editText.addTextChangedListener(textWatcher);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search