Select Text From Textview?
Is it possible to select text from a TextView(including highlight) ? It is possible with EditText but i need that to be done using TextView .. Any help regarding this please ? Than
Solution 1:
Use this:
android:textIsSelectable="true"
as easy as pie ;)
Edit:
setting it in code: textView.setTextIsSelectable(true)
Solution 2:
Not sure exactly what you are going for, and this may not be exactly what you want, but you can register it for a ContextMenu and then use onCreateContextMenu
and the CLIPBOARD_SERVICE
:
privateTextView mTextView;
protected final voidonCreate(Bundle savedInstanceState) {
...
registerForContextMenu(mTextView);
}
@OverridepublicvoidonCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
TextView textView = (TextView) view;
menu.setHeaderTitle(textView.getText()).add(0, 0, 0, R.string.menu_copy_to_clipboard);
}
@OverridepublicbooleanonContextItemSelected(MenuItem item) {
((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText(mTextView.getText());
returntrue;
}
Solution 3:
Actually, you do not have to develop this feature by yourself. You just need to use EditText instead TextView, while you set the android:editable of EditText to false.
My answer is here, hope it may help you:
Post a Comment for "Select Text From Textview?"