@Test public void onClick_shouldClearSelection() { final TestContext context = new TestContext(application); final TextView textView = new TextView(context); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setFocusable(true); textView.setFocusableInTouchMode(true); final LinkSpan linkSpan = new LinkSpan("test_id"); SpannableStringBuilder text = new SpannableStringBuilder("Lorem ipsum dolor sit"); textView.setText(text); text.setSpan(linkSpan, 0, 5, 0); Selection.setSelection(text, 0, 5); linkSpan.onClick(textView); assertThat(Selection.getSelectionStart(textView.getText())).isEqualTo(0); assertThat(Selection.getSelectionEnd(textView.getText())).isEqualTo(0); }
@Override public void onClick(View view) { if (dispatchClick(view)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.cancelPendingInputEvents(); } } else { Log.w(TAG, "Dropping click event. No listener attached."); } if (view instanceof TextView) { CharSequence text = ((TextView) view).getText(); if (text instanceof Spannable) { Selection.setSelection((Spannable) text, 0); } } }
LinkSpan extends ClickableSpan { @Override public void onClick(View view) { if (dispatchClick(view)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.cancelPendingInputEvents(); } } else { Log.w(TAG, "Dropping click event. No listener attached."); } if (view instanceof TextView) { CharSequence text = ((TextView) view).getText(); if (text instanceof Spannable) { Selection.setSelection((Spannable) text, 0); } } } }
LinkSpan extends ClickableSpan { @Override public void onClick(View view) { if (dispatchClick(view)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.cancelPendingInputEvents(); } } else { Log.w(TAG, "Dropping click event. No listener attached."); } if (view instanceof TextView) { CharSequence text = ((TextView) view).getText(); if (text instanceof Spannable) { Selection.setSelection((Spannable) text, 0); } } } LinkSpan(String id); }
LinkSpan extends ClickableSpan { @Override public void onClick(View view) { if (dispatchClick(view)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.cancelPendingInputEvents(); } } else { Log.w(TAG, "Dropping click event. No listener attached."); } if (view instanceof TextView) { CharSequence text = ((TextView) view).getText(); if (text instanceof Spannable) { Selection.setSelection((Spannable) text, 0); } } } LinkSpan(String id); @Override void onClick(View view); @Override void updateDrawState(TextPaint drawState); String getId(); }
LinkSpan extends ClickableSpan { @Override public void onClick(View view) { if (dispatchClick(view)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.cancelPendingInputEvents(); } } else { Log.w(TAG, "Dropping click event. No listener attached."); } if (view instanceof TextView) { CharSequence text = ((TextView) view).getText(); if (text instanceof Spannable) { Selection.setSelection((Spannable) text, 0); } } } LinkSpan(String id); @Override void onClick(View view); @Override void updateDrawState(TextPaint drawState); String getId();  }