In one touch i want to get a option to select and copy the text from textview like the image show here.
Asked
Active
Viewed 4,896 times
3 Answers
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"/>

Kumait
- 702
- 8
- 15
2
just add this to your TextView
xml file :
android:textIsSelectable="true"

Soheil Setayeshi
- 2,343
- 2
- 31
- 43
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
}
});
-
1but how to get a portion of text from that textview – daffodils Oct 20 '11 at 08:16
-
You have to make your TextView Spannable, refer [to this](http://stackoverflow.com/questions/2120035/highlight-text-in-textview-or-webview) or better [this](http://stackoverflow.com/questions/6309093/how-to-allow-the-user-to-select-a-text-range-in-a-textview-similar-to-edittext/7035836#7035836) – Reno Oct 20 '11 at 08:20
-
hi Reno thanks for your suggestion ..but how to give onclick option to textview dynamically? – daffodils Oct 21 '11 at 06:34
-
i created that textview through java code..so how to give on click option for that textview . – daffodils Oct 21 '11 at 06:41