how set ClickListener on drawable in Drawable class in android?

huangapple go评论144阅读模式
英文:

how set ClickListener on drawable in Drawable class in android?

问题

我有一个继承自Drawable的类。
我在其上绘制一些View。我有一个需要在其上设置ClickListenerdrawable
我搜索了很多,根据这个链接,我们对于这个类没有监听器!
有人可以帮助我吗?谢谢。

英文:

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

答案1

得分: 1

根据您已经提供的文档,

> Drawable 是一个用于“可以绘制的内容”的一般抽象表示;
>
>...
>
>
> 与 View 不同,Drawable 无法 接收任何事件或与用户进行交互。

由于 View 提供了一个接收点击事件的方法(setOnClickListener),以及一个将其前景设置为 Drawable 的方法(setForeground),为什么不使用这些呢?

英文:

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?

答案2

得分: 0

没有直接在Drawable上设置点击监听器的方法。你应该使用setImageDrawable(...)Drawable放入ImageView中。

然后,您可以像在任何其他View上一样,使用setOnClickListenerImageView上设置点击监听器。

英文:

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.

huangapple
  • 本文由 发表于 2020年5月31日 00:51:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/62105765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定