bhaskar bhaskar - 3 days ago 4
Android Question

how to make Relative layout onclick work?

I have a Relative layout as:

<RelativeLayout
android:id="@+id/iPay_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="· Use iPay"
android:textColor="#686A86"
android:textSize="18sp" />


<Button
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:background="@drawable/i_pay"
android:textAllCaps="false"
android:textColor="#ffffff" />

</RelativeLayout>


I want my relative layout to perform onCLickListener but does not work.
I am able to do the setonclicklistener but it works only with the textview part and not for the image.

btniPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//for ipay

}
});


This works for the text part only but not for the image. Any idea what I might be missing.

Answer

Alternatively, you can add android:clickable="false" in your button xml attribute.

<RelativeLayout
    android:id="@+id/iPay_btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:orientation="horizontal">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="· Use iPay"
        android:textColor="#686A86"
        android:textSize="18sp" />


    <Button
        android:layout_width="50dp"
        android:layout_height="35dp"
        android:layout_alignParentRight="true"
        android:background="@drawable/i_pay"
        android:textAllCaps="false"
        android:clickable="false"
        android:textColor="#ffffff" />

</RelativeLayout>
Comments