Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make text in a TextView unclickable in the layout XML?

I have different table rows, each of it contains some information text which should not be clickable and not selectable. But when I run this in the emulator, the text is always clickable.

That means, when I click on any text block, its color changes to a dark grey. I don't want it to change. I want it to do nothing.

Surely, I could set the dark grey to the text color so the user doesn't see that he clicks anything, but this is not what I want.

I already tried different attributes as you can see in the example, but nothings help. Moreover, what do I actually have to set not clickable, the TableRow or the TextView inside the TableRow?

Here is an example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    >
    <ScrollView 
            android:id="@+id/scrollView"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal">
    <TableLayout 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:stretchColumns="*"
            android:clickable="false">
        <TableRow
            android:layout_width="fill_parent"
            android:background="#777777"
            android:clickable="false">
            <TextView 
                 android:id="@+id/heading"
                 android:text="This is the cool heading"             
                 android:textColor="#FFFFFF"
                 android:layout_width="fill_parent"
                 android:textSize="14sp"
                 android:paddingLeft="5sp"
                 android:paddingRight="5sp"
                 android:paddingTop="2sp"
                 android:paddingBottom="2sp"
                 android:textStyle="bold" 
                 android:clickable="false"  
                 />
        </TableRow>
         <TableRow
             android:clickable="false"
             android:linksClickable="false"
             android:focusable="false"
             android:focusableInTouchMode="false">
            <TextView
                 android:text="This is example text. It should not be clickable, but it is."
                 android:textSize="14sp"
                 android:paddingLeft="5sp"
                 android:paddingRight="5sp"
                 android:paddingTop="2sp"
                 android:paddingBottom="2sp"
                 android:scrollHorizontally="false"
                 android:inputType="textMultiLine"
                 android:linksClickable="false"
                 android:clickable="false"
                 android:focusable="false"
                 android:focusableInTouchMode="false"
                 android:layout_width="0sp"
                 />
               </TableRow>
              </TableLayout>
              </ScrollView>
              </RelativeLayout>
like image 921
Bevor Avatar asked Nov 30 '22 15:11

Bevor


1 Answers

I found the solution, when I add android:longClickable="false" to the TextView, it works. And I only need those two settings in TextView in all:

android:longClickable="false"
android:clickable="false"

Settings in TableRow are not needed.

like image 76
Bevor Avatar answered Dec 04 '22 20:12

Bevor