I have my field declared and with campo.setSelectionStart(0)
and campo.setSelectionEnd(12)
I get the text to be selected but I can't check if this text is selected. I'm looking for something like campo.isTextSelected()
or something that goes along that line.
Try this:
if (campo.getSelectionEnd()==campo.getText().length()) {
reutrn true;
}
But getSelectionEnd()
it always keeps growing and gives me true indistinctly. The idea is to limit the number of characters that I write but if it is selected, no, so that the selection is overwritten.
I can only think of your method
boolean
simply containing:return campo.getSelectedText() != null;
...and then one or the other happens:
We obtain
true
if there is text with highlight, basically because itgetSelectedText()
would contain and return a dataString
that would automatically make it different fromnull
.We obtain
false
when we have no selected text, since itgetSelectedText()
will be equal tonull
.I hope it helps.