TextView tv; String stringYouExtracted = tv.getText().toString; int startIndex = tv.getSelectionStart(); int endIndex = tv.getSelectionEnd(); stringYouExtracted = stringYouExtracted.subString(startIndex, endIndex); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(stringYouExtracted);
private void captureValues(TransitionValues transitionValues) { if (transitionValues.view instanceof TextView) { TextView textview = (TextView) transitionValues.view; transitionValues.values.put(PROPNAME_TEXT, textview.getText()); if (textview instanceof EditText) { transitionValues.values.put(PROPNAME_TEXT_SELECTION_START, textview.getSelectionStart()); transitionValues.values.put(PROPNAME_TEXT_SELECTION_END, textview.getSelectionEnd()); } if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) { transitionValues.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor()); } } }
private void captureValues(TransitionValues transitionValues) { if (transitionValues.view instanceof TextView) { TextView textview = (TextView) transitionValues.view; transitionValues.values.put(PROPNAME_TEXT, textview.getText()); if (textview instanceof EditText) { transitionValues.values.put(PROPNAME_TEXT_SELECTION_START, textview.getSelectionStart()); transitionValues.values.put(PROPNAME_TEXT_SELECTION_END, textview.getSelectionEnd()); } if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) { transitionValues.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor()); } } }
public S hasSelectionEnd(int position) { isNotNull(); int actualPosition = actual.getSelectionEnd(); assertThat(actualPosition) // .overridingErrorMessage("Expected selection end <%s> but was <%s>.", position, actualPosition) // .isEqualTo(position); return myself; }
.getText() .subSequence(tv.getSelectionStart(), tv.getSelectionEnd()).toString(); Log.d("tapped on:", s);
@Test public void append_whenSelectionReachesToEnd_shouldExtendSelectionToTheEnd() throws Exception { textView.setText("12", TextView.BufferType.EDITABLE); Selection.setSelection(textView.getEditableText(), 0, 2); textView.append("3"); assertEquals(3, textView.getSelectionEnd()); assertEquals(0, textView.getSelectionStart()); }
@Test public void append_whenSelectionIsAtTheEnd_shouldKeepSelectionAtTheEnd() throws Exception { textView.setText("1", TextView.BufferType.EDITABLE); Selection.setSelection(textView.getEditableText(), 0, 0); textView.append("2"); assertEquals(0, textView.getSelectionEnd()); assertEquals(0, textView.getSelectionStart()); Selection.setSelection(textView.getEditableText(), 2, 2); textView.append("3"); assertEquals(3, textView.getSelectionEnd()); assertEquals(3, textView.getSelectionStart()); }
tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TextView tv = (TextView)v; if(! (tv.getSelectionStart()==-1 && tv.getSelectionEnd()==-1)) // Fired only when you touch the part of the text that is hyperlinked // do something }
TextView textView; String stringToBeExtracted; int startingIndex=textView.getSelectionStart(); int endingIndex=textView.getSelectionEnd(); stringToBeExtracted = stringYouExtracted.subString(startingIndex, endingIndex); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(stringToBeExtracted); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("Text Copied", stringToBeExtracted); clipboard.setPrimaryClip(clip); }
TextView tv; String stringYouExtracted = tv.getText().toString; int startIndex = tv.getSelectionStart(); int endIndex = tv.getSelectionEnd(); stringYouExtracted = stringYouExtracted.subString(startIndex, endIndex);
TextView txtview; String stringSelected = txtview.getText().toString; int startIndex = txtview.getSelectionStart(); int endIndex = txtview.getSelectionEnd(); stringSelected = stringSelected.subString(startIndex, endIndex); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clpbrd = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(stringSelected); } else { android.content.ClipboardManager clpbrd = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", stringSelected); clipboard.setPrimaryClip(clip); }
public S hasSelectionEnd(int position) { isNotNull(); int actualPosition = actual.getSelectionEnd(); assertThat(actualPosition) // .overridingErrorMessage("Expected selection end <%s> but was <%s>.", position, actualPosition) // .isEqualTo(position); return myself; }
TextView tv; String stringYouExtracted = tv.getText().toString; int startIndex = tv.getSelectionStart(); int endIndex = tv.getSelectionEnd(); stringYouExtracted = stringYouExtracted.subString(startIndex, endIndex); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(stringYouExtracted);
private void setSelectedSpan(TextView tv) { if (mSelectedBackSpan == null || mSelectedForeSpan == null) { mSelectedBackSpan = new BackgroundColorSpan(selectedColor); mSelectedForeSpan = new ForegroundColorSpan(Color.WHITE); } else { mSpannableString.removeSpan(mSelectedBackSpan); mSpannableString.removeSpan(mSelectedForeSpan); } mSpannableString.setSpan(mSelectedBackSpan, tv.getSelectionStart(), tv.getSelectionEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mSpannableString.setSpan(mSelectedForeSpan, tv.getSelectionStart(), tv.getSelectionEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); GetWordTextView.super.setText(mSpannableString, mBufferType); }
@Override public void onClick(View widget) { TextView tv = (TextView) widget; int startIndex = tv.getSelectionStart(); int endIndex = tv.getSelectionEnd(); if (TextUtils.isEmpty(getText()) || startIndex == -1 || endIndex == -1) { return; } String word = tv .getText() .subSequence(startIndex, endIndex).toString(); setSelectedSpan(tv); if (mOnWordClickListener != null) { mOnWordClickListener.onClick(word); } }
text.setSpan(new StyleSpan(Typeface.BOLD),tv.getSelectionStart(),tv.getSelectionEnd(),0); text.setSpan(new StyleSpan(Typeface.NORMAL),tv.getSelectionStart(),tv.getSelectionEnd(),0);
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { Log.e("", String.format("onActionItemClicked item=%s/%d", item.toString(), item.getItemId())); CharacterStyle cs; TextView bodyView = null; int start = bodyView.getSelectionStart(); int end = bodyView.getSelectionEnd(); SpannableStringBuilder ssb = new SpannableStringBuilder(bodyView.getText()); /*Toast.makeText(getActivity(), (String)data.result, Toast.LENGTH_LONG).show();*/ Toast.makeText(this, " toast shown ", Toast.LENGTH_LONG).show(); switch (item.getItemId()) { case R.id.bold: cs = new StyleSpan(Typeface.BOLD); ssb.setSpan(cs, start, end, 1); bodyView.setText(ssb); return true; case R.id.italic: cs = new StyleSpan(Typeface.ITALIC); ssb.setSpan(cs, start, end, 1); bodyView.setText(ssb); return true; case R.id.underline: cs = new UnderlineSpan(); ssb.setSpan(cs, start, end, 1); bodyView.setText(ssb); return true; } return false; }
TextView t1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); t1=(TextView) findViewById(R.id.textView1); t1.setTextIsSelectable(true);// IMPORTANT t1.setText("This is Android program"); t1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch(event.getAction()){ case MotionEvent.ACTION_UP: int start=t1.getSelectionStart(); int end=t1.getSelectionEnd(); String sub=t1.getText().subSequence(start, end).toString(); Toast.makeText(getBaseContext(), sub, 1).show(); } return true; } }); }
private int getEndPos(TextView widget) { int end; if (widget.getSelectionStart() == mManager.getSelectionStart()) { end = widget.getSelectionEnd(); } else { end = widget.getSelectionStart(); } return end; }
@Override public void onClick(View v) { // This condition will satisfy only when it is not an autolinked // text // onClick action boolean isNotLink = layout.recontent.getSelectionStart() == -1 && layout.recontent.getSelectionEnd() == -1; boolean isDeleted = msg.getRetweeted_status() == null || msg.getRetweeted_status().getUser() == null; if (isNotLink && !isDeleted) { startActivity(BrowserWeiboMsgActivity.newIntent(BeeboApplication.getInstance().getAccountBean(), msg.getRetweeted_status(), BeeboApplication .getInstance().getAccessTokenHack())); } else if (isNotLink) { Toast.makeText(getActivity(), getString(R.string.cant_open_deleted_weibo), Toast.LENGTH_SHORT).show(); } } };