Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accepting click events in RelativeLayout

Tags:

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?

like image 561
skooter Avatar asked Jun 01 '10 11:06

skooter


2 Answers

Just add a OnClickListener to your RelativeLayout

like image 189
RoflcoptrException Avatar answered Oct 18 '22 05:10

RoflcoptrException


I have a RelativeLayout called "RelativeMain1". This is how i make it start Activity

RelativeLayout relativeclic1 =(RelativeLayout)findViewById(R.id.RelativeMain1);          relativeclic1.setOnClickListener(new View.OnClickListener(){              @Override              public void onClick(View v){                  startActivityForResult(new Intent(A_My_Galaxy.this,C_Student_Book_Planet.class), 0);              }          }); 

After you add the onClickListener to your layout, it should work.

like image 37
Gimsi Avatar answered Oct 18 '22 05:10

Gimsi