Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selectionCursor on single click in a textview

Tags:

android

Is it possible to get selection cursor on single click in a textview. By default, we get selection cursor when long click is performed. Selected text needs to appear in edittext below. I've tried using spannable string, so the tapped string comes in edittext, but i want the user to be able to modify the selection with selection cursor.

enter image description here

like image 859
PK Gupta Avatar asked Dec 08 '25 10:12

PK Gupta


2 Answers

android:textIsSelectable works. So the problem is that when you set the flag editable to false setKeyListener is called and the focusable flag is overwritten.

To fix it, in the onCreate of my activity You should add:

tesxtView.setKeyListener(null);
tesxtView.setFocusable(true);
like image 177
Meenakshi Mishra Avatar answered Dec 09 '25 23:12

Meenakshi Mishra


try this:

 yourTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
         ClipboardManager clipboard =
        (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
    clipboard.setText(yourTextView.getText());
        }
    });
like image 24
KDeogharkar Avatar answered Dec 09 '25 22:12

KDeogharkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!