0

enter image description hereit may be duplicated ,i searched for the answer but unfortunately i didn't found the answer .. i have relative layout that is nested with table row and and image view and text view

<!--  add photo image  -->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_margin="5dp"
    android:layout_weight="1.5"
    android:id="@+id/layot_attach"
    android:clickable="true"
    android:focusable="true"
    android:background="@drawable/photo_button_selector"
    android:layoutDirection="rtl">



    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/ic_add_photo_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:focusable="false"
            android:clickable="false"
            android:src="@drawable/ic_attach_file_white_48dp"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal|center_vertical"
            android:textColor="@color/white"
            android:id="@+id/textView_attach"
            style="@style/title"
            android:padding="5dp"
            android:layout_weight="1" />


        <ImageView
            android:id="@+id/preview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp" />
    </TableRow>
</RelativeLayout>

and when i click on the layout my method is called except when i click on the first nested image view (ic_add_photo_image)
i added the clickable and focusable withe false values to the image view but that dosent some to work

here is my selector photo_button_selector

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
      android:drawable="@drawable/photo_button_pressed" /> <!-- pressed -->

<item android:drawable="@drawable/photo_button" /> <!-- default -->

did i miss any thing , can some one help me to fix it or explain ?

here is my listner :

layoutattach = (RelativeLayout) findViewById(R.id.layot_attach);
layoutattach.setOnClickListener(this); // method called 

EDIT

i didnot solve the proplem the way i wanted to
i declared my image icon in the code and attach alistenr to it .. i lost the effect of button click .. but that will do it for now

danny
  • 147
  • 1
  • 15
  • Set `OnClickListener` on the relative layout in your activity. Access RelativeLayout with ID. Refer this link - https://stackoverflow.com/questions/3320115/android-onclicklistener-identify-a-button – Onkar Nene May 30 '17 at 08:56
  • Possible duplicate of [Android OnClickListener - identify a button](https://stackoverflow.com/questions/3320115/android-onclicklistener-identify-a-button) – Onkar Nene May 30 '17 at 08:57
  • @OnkarNene i i did add listener ass you see above i just didnt post here the on click method !! – danny May 30 '17 at 09:00
  • In Layout file, You are setting `android:layout_height="0dp"`. Replace `0dp` with `wrap_content`. Also `android:layout_weight="1.5"` attribute is work with only LinearLayout. So don't use `layout_weight` for RelativeLayout. – Onkar Nene May 30 '17 at 09:05

2 Answers2

1

Try this below solution add below attribute in Relative Layout:-

android:background="?android:attr/selectableItemBackground"
Nitin Patel
  • 1,605
  • 13
  • 31
0

I think you need like this, full portion of layout clickable or other elements,so try this.

Your Parent layout (Relative layout)having attribute:-

android:descendantFocusability="blocksDescendants"
sagar potdar
  • 598
  • 1
  • 6
  • 22