0

I have a custom widget (InfoIcon) with two views (Image view and Text View). I used this custom widget (InfoIcon) in my main layout file multiple times with individual Id (infoIconOne, infoIconTwo, infoIconThree) for the whole custom widget. Now want to listen only to the ImageView (inside Custom widget) onClick events and how to identify whether the ImageView click happens in infoIconOne/infoIconTwo/infoIconThree in parent layout?

InfoIcon:

<RelativeLayout
    android:id="@+id/icon_layout">
    <ImageView
        android:id="@+id/image_icon"
        android:src="@drawable/icon" />
    <TextView
        android:id="@+id/icon_info_text"/>
</RelativeLayout>

MainLayout:

<android.support.constraint.ConstraintLayout
    android:id="@+id/parent_container">
    <InfoIcon
        android:id="@+id/iconOne"/>
    <InfoIcon   
        android:id="@+id/iconTwo"/>
    <InfoIcon   
        android:id="@+id/iconThree"/>
</android.support.constraint.ConstraintLayout>
Zoe
  • 27,060
  • 21
  • 118
  • 148
Anushiya
  • 25
  • 9

1 Answers1

0

findViewById(R.id.infoIconOne).findViewById(R.id.image_icon).setOnClickListener{...}

and you need to do it for all imageviews with there id

Vladyslav Ulianytskyi
  • 1,401
  • 22
  • 22
  • Yes, Thanks for the solution. But on clicking anyone of the three icon in the layout , onClick(View v) will get triggered with the view "image_icon". Now how I could able to differentiate whether the image_icon is from iconOne or iconTwo or iconThree? – Anushiya Jun 23 '19 at 09:22
  • I fixed the problem by using (View)view. getParent() in onClick() function to differentiate between iconOne or iconTwo or iconThree in layout – Anushiya Jun 23 '19 at 09:50