Reputation: 80
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
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
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