Select part of a string in EditText

b4AMarkO

Member
Licensed User
Longtime User
When I press and hold over text in edittext it
Highlights the whole string ..... then I can slide the highlight to what part of the text I wish to copy or modify

But can I do this OK-ABC123 in Edittext

Press and Hold and only ABC123 be highlighted? possibly through string functions using - as a delimiter maybe?

Help Appreciated
 

JesseW

Active Member
Licensed User
Longtime User
Yes, you can, but not through string manipulation. You have to use a Reflector object to access the highlighted portion of the edittext. Here are some examples. These are by hand, so there may be mistakes

Determine if any text is selected
B4X:
dim edt as edittext
dim obj1 as reflector
...
dim ok as boolean
obj1.target = edt
ok = obj1.runmethod("hasSelection")  'note: hasSelection is case sensitive!

To manually set the selection
B4X:
obj1.target = edt
obj1.runmethod3("setSelection", selstart, "java.lang.int", selstart + sellength, "java.lang.int")  'Note: setSelection is case sensitive!
You will have to determine where you want the start of the selection and how long you want it.

Hope this helps..
Jesse
 
Upvote 0

b4AMarkO

Member
Licensed User
Longtime User
This looks interesting .... forgive my ignorance on the subject but how do I implement this for testing

I assume that this below are in Globals


B4X:
dim edt as edittext
dim obj1 as reflector

But the rest?
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
the rest would simply be where you needed the functionality. I can'tdecide that for you, but it may be in the edittext's events perhaps. I use the functionality in b4script when the user uses the 'find' menu options to highlight where the next match is. for you it will depend on the dynamics of the app you're building. good luck :)
 
Upvote 0
Top