How to make multiple Textview selectable in a activity?

1.4k Views Asked by At

I am developing an Android app. It is just like an article reading app in which there are many textview (more than 10) under one activity. Like -

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".EnviarMensaje">
    <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
    <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
    <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
</RelativeLayout>

I want to make all these textview selectable when user touch for a long time on text, an option should come "select all". And when choosing the select all option, the Text of all Textview (From textView 1 to textView3) should select. I tried - android:textIsSelectable=true But after apply this, when I choose select all option, the Text is selected of only textView1 or textView2. Not selected all text on screen together. Please help me.

1

There are 1 best solutions below

0
On

Checkout this: https://stackoverflow.com/a/6179365

You can register the textviews in onCreate, then override onCreateContextMenu and getTextfrom each textview.