[Single Line Widget][Android] Condition to trigger `onSelectionChanged`event

Hello MyScript Team,

I would like to get all recognized candidates in the Box Mode using the Single Line Widget. After studying the sample codes in ATK, I knew that we could get that in onSelectionChanged event. But I failed to trigger that event every time after writing in a box. In fact, the method onSelectionChanged() is called only for the first box.

Could you please point out the exact condition to trigger this onSelectionChanged event? Also, could you explain the relation among cursor index, index of insertion mode and the start & end of selection?

Thanks a lot.


Firstly it could be helpful to get more details about your use case in order to better answer your needs.
Why do you choose the 'Box mode'? What would you like to do with the candidates?

In our sample, we use a 'CustomEditText' field (CustomEditText.java). It calls 'setCursorIndex' function every time a character is written and triggers a 'OnSelectionChanged' event. This way, you should be able to get recognition labels. Using a Textview in BoxMode, we have reproduced the problem you reported us (OnselectionChanged only occurs for the first box), so if you prefer a Textview, you will have to call 'setCursorIndex' function as we do in the sample as there's no specific api to get recognition candidates.

public class CustomEditText extends EditText
public interface OnCursorIndexChangedListener {
public void onCursorIndexChanged(int index);

private OnCursorIndexChangedListener mOnCursorIndexChangedListener;

public CustomEditText(final Context context, final AttributeSet attrs)
super(context, attrs);

public void setOnCursorIndexChangedListener(final OnCursorIndexChangedListener l)
mOnCursorIndexChangedListener = l;

protected void onSelectionChanged(final int selStart, final int selEnd)
super.onSelectionChanged(selStart, selEnd);

if (mOnCursorIndexChangedListener != null) {

public void setCursorIndex(int index)
final Editable editable = getText();
int length = 0;
if(editable != null)
length = editable.length();

if (index < 0) {
index = 0;
if (index > length) {
index = length;


Hope it could help you. Getting more details about your use case would be useful to suggest the most appropriate solution.
Best regards

Thank you Cate, your reply indeed helps a lot.I am able to trigger the event every time now.

What I want to achieve here is to let user write a list of given characters and use the candidates to evaluate the result.

I would like to ask you one more question. Why sometimes the recognition result shows in the box, but at most of time it's just blank? (I disabled auto scroll)

Thanks again.

Sorry for the delay, do you still need help on this topic?
In that case, could you please give more details in order to reproduce such issue?
Best regards

Login or Signup to post a comment
  • Support
  • Forums
  • Text
  • [Single Line Widget][Android] Condition to trigger `onSelectionChanged`event