Search code examples
androidandroid-edittext

EditText - Get text from EditText while typing


I want to get the text into some String in my app while the user is typing in the EditText and use it to lively show it on the activity (in different View...) - Just like google's live/instant search works...


Solution

  • You are looking for TextWatcher:

        youredittext.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void afterTextChanged(Editable mEdit) 
            {
                text = mEdit.toString();
            }
    
            public void beforeTextChanged(CharSequence s, int start, int count, int after){}
    
            public void onTextChanged(CharSequence s, int start, int before, int count){}
        });