Search code examples
androidandroid-layouttextview

Android TextView is not clickable


I have this small piece of code, and I started using relative layouts and the textview is no longer clickable. I am posting the XML below.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/fav_list_selector"
 android:orientation="horizontal"
 android:padding="5dip">    
<ImageButton
    android:id="@+id/pinImage"
    android:layout_alignParentLeft="true"
    android:src="@drawable/ic_9_av_make_available_offline"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"/>    
<TextView
    android:id="@+id/favBusItem"
    android:layout_toRightOf="@+id/pinImage"
    android:layout_toLeftOf="@+id/transpoImage"
    android:layout_centerVertical="true"
    android:textSize="12sp"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"     
    android:clickable = "true"   
    android:textColor="#000000">        
</TextView>    
<ImageButton
    android:id="@+id/transpoImage"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/pinImage"
    android:src="@drawable/ic_9_av_make_available_offline"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"/>    
</RelativeLayout>

I suspect that the textview is not clickable because of the ImageButton.


Solution

  • Well, I figured it out myself.. Anyway here is the answer in case anyone else hits the same issue:

    add this attribute for your imagebutton

     android:focusableInTouchMode="false"
    

    also add

     android:descendantFocusability="blocksDescendants" 
    

    for your parent layout

    This worked for me