3

In one touch i want to get a option to select and copy the text from textview like the image show here.

enter image description here

0

3 Answers 3

2

In your onClickListener for the TextView:

ClipboardManager clipboard =
    (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
clipboard.setText(yourTextView.getText());

ed : Answer to the question in comments :

  yourTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO: add your code here

        }
    });
Sign up to request clarification or add additional context in comments.

4 Comments

but how to get a portion of text from that textview
You have to make your TextView Spannable, refer to this or better this
hi Reno thanks for your suggestion ..but how to give onclick option to textview dynamically?
i created that textview through java code..so how to give on click option for that textview .
2

Just Set "textIsSelectable" on the TextView to true

    <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Detail Text"
                android:id="@+id/txtBody"
                android:background="@android:color/white"
                android:gravity="right"
                android:textColor="@android:color/black"
                android:textSize="16sp"
                android:padding="5dp"
                android:enabled="true"
                android:textIsSelectable="true"/>

Comments

2

just add this to your TextView xml file :

android:textIsSelectable="true"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.