OnClick Listener not working for buttons which exists in a linearlayout for which the alignParentBottom is true

368 views Asked by At

I am having an activity and want to create a like button at the end of the layout, So I created a layout file and in a LinearLayout I have set it's layout_alignParentBottom property to true and created button for Likes in it. Now I am including this layout file in some other layout file but when I am applying onClickListener to the button, it does nothing.

When I remove this layout_alignParentBottom from the LinearLayout properties, then OnclickListener start working.

Can you please help me here to resolve this issue?

1

There are 1 answers

1
Neal Ahluvalia On

Some other widget might be coming in its way. if there is something above that button, it wont take clickListener.

For Ex. if there is a list in that layout too,

<Button
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="@dimen/viewSpace1"
    android:layout_marginRight="@dimen/viewSpace1"
    android:layout_marginBottom="@dimen/viewSpace1"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/headerHeight_small"
    android:id="@+id/btnShare"
    style="@style/ButtonLogin"
    android:text="Next" />

<ListView 
    android:layout_above="@id/btnShare"
    android:id="@+id/list"
    android:layout_below="@id/layoutHeader"
    android:layout_marginLeft="@dimen/viewSpace3"
    android:layout_marginRight="@dimen/viewSpace3"
    android:layout_marginBottom="@dimen/viewSpace3"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" />  

so your share button stays safe for clickability. I have kept the list above btnShare. Just for my safety if it overlaps the button.If there is still problem, post your code so exact problem can be pin pointed.