英文:
how set ClickListener on drawable in Drawable class in android?
问题
我有一个继承自Drawable的类。
我在其上绘制一些View。我有一个需要在其上设置ClickListener的drawable!
我搜索了很多,根据这个链接,我们对于这个类没有监听器!
有人可以帮助我吗?谢谢。
英文:
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上一样,使用setOnClickListener在ImageView上设置点击监听器。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论