accepting click events in RelativeLayout

skooter picture skooter · Jun 1, 2010 · Viewed 45.1k times · Source

I have a RelativeLayout with a few TextView as children

<RelativeLayout
    android:id="@+id/shift_parent_name"
    android:layout_width="fill_parent"
    android:layout_weight="0.25"
    >
    <TextView
        android:id="@+id/shift_parent_nametitle"
        android:text="@string/shift_parent_nametitle"
        style="@style/header_text"
        />
    <TextView
        android:id="@+id/shift_parent_namefield"
        android:layout_alignParentRight="true"
        android:layout_below="@id/shift_parent_nametitle"
        style="@style/wrap"
        />

How do I go about using the RelativeLayout as a button to react to a click event if any part of the area is pressed?

Answer

RoflcoptrException picture RoflcoptrException · Jun 1, 2010

Just add a OnClickListener to your RelativeLayout