Reputation: 1716
I have got a text like "ABC XYZ"
//Below Code selects ABC and clears it and enter 123 , resulting in "123 XYZ"
editText.setText("123");
Is there a way I can select the entire string even if it has spaces in it.
Upvotes: 0
Views: 1349
Reputation: 8358
You can use below workaround :
String text = editText.getText();
editText.clickBottomRight();
for (int i=0;i<text.length();i++) {
UiDevice.getInstance().pressDelete();
}
editText.setText("123");
Upvotes: 3
Reputation: 96
Can't you try this instead, This will clear the editText box value and then set it.
editText.clearText();
editText.setText("123");
Upvotes: 0
Reputation: 1
This is the workaround I'm using:
editText.longClick();
pause for 50 ms:
//UiObject selectAll = new UiObject(new UiSelector().descriptionContains("Select all"));
selectAll.click();
pause for 250 ms:
//UiDevice dev = getInstance();
dev.pressKeyCode(KeyEvent.KEYCODE_DEL, 0);
You might want to play with pause.
Upvotes: -1