5

How can I make a TextView selectable in API <= 11 ? I search a lot and found that i could use Editext as a TextView, but this away don't looks good anyway, and I need to send the part selected of a text to a new Activity, Someone could help me with this ?

A example of what i'm searching for is the Onlongclick pressed in app OperaMini. After a long click he opens a cursor for the user select that part of the text that him Need and a ContextMenu for that selected part.

Thank's.

enter image description here

I need to make something like this Print, when longclinck, make appears the selectors of text(the blue tips on the print) and show the part selected.

FpontoDesenv
  • 162
  • 1
  • 13

1 Answers1

14

You either in xml make it selectable

        android:textIsSelectable="true"

or making your textview clickable by assigning it a Onclicklistener

  TextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
        clipboard.setText(TextView.getText());
        }
    });
Ahmed Ekri
  • 4,601
  • 3
  • 23
  • 42
  • 1
    please accept the answer ( the tick ) if it helped you. and welcome to stackOverFlow – Ahmed Ekri Aug 25 '13 at 07:45
  • Thank you @Ahmed-Ekri, but doesn't work. I try the two forms that you say but nothing happen in my TextView. – FpontoDesenv Aug 25 '13 at 15:05
  • Someone could help me ? Please – FpontoDesenv Aug 26 '13 at 01:06
  • It works but not in all apis' .. so use this library to get a working clipboard in all apis' https://github.com/commonsguy/cw-advandroid/tree/master/SystemServices/ClipIP .. please accept and rate the question if it helps – Ahmed Ekri Sep 06 '13 at 08:16
  • it works to copy. Thanks a lot. I have now just a dubt. How Can i get a range of text to send for clipboardManager ? – FpontoDesenv Oct 13 '13 at 15:17
  • Ok, but... How Can I display the cursor to the user select the range of text like the print? Thank you, really @AhmedEkri. – FpontoDesenv Oct 15 '13 at 03:16