NeoKerd
NeoKerd

Reputation: 219

Select and copy text in a TextView Android

I know there is another question just like this one but still haven't answer working for me.

I have a TextView in my fragment with informations inside.It's a long textview with a scrolling bar. I want to copy paste some information but can't select and copy.

There is my TextView :

<TextView
            android:id="@+id/tv_observ_client"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="40dp"
            android:textIsSelectable="true"
            android:layout_marginEnd="5dp"
            android:textColor="@android:color/black"
            android:scrollbars="vertical"
            android:enabled="true"
            android:focusable="true"
            android:longClickable="true"
            android:text="Info pratiques " />

I'm able to copy all the TextView's but I only want some information.

Thank's


EDIT

This is all the layout, it may help :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragments_info_client.Coordonne_client"
    android:orientation="vertical">

    <!-- TODO: Update blank fragment layout -->
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
        android:orientation="horizontal">

    <TextView
        android:id="@+id/tv_nom_cli"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:textColor="@android:color/black"
        android:text="Nom client"
        android:textStyle="bold">


    </TextView>
        <TextView
            android:id="@+id/tv_codeP_cli"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"
            android:text="Code postal client"
            android:layout_marginStart="10dp">
        </TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="5dp">

        <TextView
            android:id="@+id/tv_adresse_cli"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="Adresse Client"
            android:textStyle="bold"
            android:textColor="@android:color/black"
             />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="5dp">

        <TextView
            android:id="@+id/tv_ville_cli"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:textColor="@android:color/black"
            android:layout_marginLeft="10dp"
            android:text="Ville Client"
            android:textStyle="bold"></TextView>

        <TextView
            android:id="@+id/tv_tel_cli"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="Tel Client"
            android:textStyle="bold"
            android:textColor="@android:color/black"
             ></TextView>
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imgBtn_tel_client"
            android:src="@drawable/call_answer"></ImageButton>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="5dp">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv_nb_hab"
            android:text="Nombre habitants : "
            android:layout_marginTop="10dp"
            android:textStyle="bold"
            android:textColor="@android:color/black"
            android:layout_marginLeft="10dp">

        </TextView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/tv_observ_client"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="40dp"
            android:textIsSelectable="true"
            android:layout_marginEnd="5dp"
            android:textColor="@android:color/black"
            android:scrollbars="vertical"
            android:enabled="true"
            android:focusable="true"
            android:longClickable="true"
            android:text="Info pratiques " />
    </LinearLayout>
</LinearLayout>

This textview is in a fragment, this fragment is handle by a viewpager adapter with differents tabs, I wonder if this case can't give the focusable(and selectable) to the textview because of the swipe action. Hope it's will help

Upvotes: 0

Views: 941

Answers (2)

NeoKerd
NeoKerd

Reputation: 219

Ok so, I found the problem by myself, I wasn't able to select because i have a

setMovementMethod(new ScrollingMovementMethod());

I tried to delete this one and it's work. Thx for ur help

Upvotes: 0

Rawal A
Rawal A

Reputation: 41

Try this:

android:textIsSelectable.

i.e., android:textIsSelectable="true"

Upvotes: 2

Related Questions