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.
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>
may be you can find some good example thats use with imageview and buttons but the easy way i did it by using adding TextView instead of images and buttons.
<RelativeLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:clickable="true"
android:gravity="right">
<TextView
android:id="@+id/englishheading1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/urduheading1"
android:text="English text"
android:textColor="#ffffff"
android:textSize="15sp" />
<TextView
android:id="@+id/urduheading1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:text="urdu text1"
android:textColor="#ffffff"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="8dp"
android:background="#ffffff" />
</RelativeLayout>
Here is java code to perform onClick
.
RelativeLayout layout1 = (RelativeLayout) view.findViewById(R.id.layout1);
layout1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do something
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With