how set ClickListener on drawable in Drawable class in android?

65 Views Asked by At

I have a class that extends from Drawable. I draw some Views on it. I have drawable that I should set ClickListener on it! I searched a lot, and according to this link, we have not listener for this class!

anybody can help me ?! Thanks

2

There are 2 best solutions below

5
Themelis On

According to documentation, which you've already provided,

A Drawable is a general abstraction for "something that can be drawn."

...

Unlike a View, a Drawable does not have any facility to receive events or otherwise interact with the user.

Since the View provides a method to receive click events (setOnClickListener) and a method which sets its foreground to a Drawable (setForeground) why don't you use that?

0
Ryan M On

There's no way to set a click listener on a Drawable directly. You should put the Drawable into an ImageView using setImageDrawable(...).

From there, you can set a click listener on the ImageView with setOnClickListener just as you would with any other View.