SlowLearnah
SlowLearnah

Reputation: 80

How do I select all the text in an editText after the user is finished typing in it?

I have an EditText with some dummy text in it. When the user finishes typing I want to be able to have all the text selected.

How can I achieve this?

Upvotes: 0

Views: 146

Answers (2)

Ankit Gupta
Ankit Gupta

Reputation: 544

Create a reference for your edittext :

EditText editText = (EditText) findViewById(/* edittext id */);

Attach a text changed listener on it :

editText.addTextChangedListener(new TextWatcher() {
    @Override
    public void afterTextChanged(Editable s) { 
        //get your final string here 
        String str = s.toString();
    }

    @Override
    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {}
});

Upvotes: 0

sadat
sadat

Reputation: 4362

You can use Rx's debounce to do that,

    RxTextView.textChanges(editText)
        .debounce(3, TimeUnit.SECONDS)
        .subscribe { textChanged: CharSequence? ->
            Log.d(
                "TAG",
                "Stopped typing!"
            )
            editText.selectAll()
        }

Upvotes: 1

Related Questions