'Change selected text in Sketchware

How can I change selected text in edittext on Sketchware by clicking button. Anyone please help me...

I am try to only change selected text in edittext. But in settext option, it change all the text of a edittext. I want to change the selected text only.

I expecting that, When I click button then selected text of edittext are change but other text in same edittext are don't change.



Solution 1:[1]

You can create one string before the selected text, and another after the selected text and put the text you want replace

So, write this in button click event:

String beforeText = edittext1.substring(0, edittext1.getSelectionStart()); String afterText = edittext1.substring(edittext1.getSelectionEnd(), edittext1.getText().toString().length());

String replaceText = "new text here";

edittext1.setText(beforeText + replaceText + afterText);

Good luck. Best regards from another Sketchware's user from Brazil

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Seth Mobit