0

How do I assign an id to a drawable in text view in the xml file.

The three dots is the drawable.

image

So I can find it by id.

findViewById<??????>(R.id.id_of_drawable)
  • 1
    You don't Drawables don't keep an id, because they may not come from a resource at all. What are you actually trying to do, and are you using a right drawable of a textview, or is it a separate view? – Gabe Sechan Apr 21 '22 at 04:47
  • In the text view I've added app:drawableEndCompat="@drawable/ic_more". I want to add setOnClickListener to the ic_more. –  Apr 21 '22 at 04:51
  • You can't. You can only put a click listener on a view. If you want to do that, you can't use an end drawable- you need to use a separate ImageView, or you need the click handler to be on the entire TextView. – Gabe Sechan Apr 21 '22 at 04:53
  • When I used ImageView in RelativeLayout or LinearLayout the Image was invisible. –  Apr 21 '22 at 04:54
  • Probably this may help you https://stackoverflow.com/a/19194441/10248593 – Jinal Patel Apr 21 '22 at 04:55
  • 1
    Then you did something wrong with the layout. That's the correct way to do this. – Gabe Sechan Apr 21 '22 at 05:27

1 Answers1

1

I used an image view next to the text view. android:srcCompat made the image invisible. When I changed it to android:src it worked.