使用具有自定义 UI 的组件创建库

发布于 2025-01-01 10:00:13 字数 513 浏览 3 评论 0原文

现在这可能是一个棘手的问题:) 问题是,我想创建一个包含所有自定义组件(例如自定义按钮、搜索栏等)的库,以便将来以更简单的方式实现它们。 但问题是我有这个圆形按钮..它现在从“ImageButton-widget”扩展 按下按钮后,我使用 onTouched-listener 来确定用户是否确实按下了圆形按钮,而不是在圆形按钮之外。因为 ImageButton-widget 被“视为”为“方形”。到目前为止,没有问题.. 但是,如果我现在想重用此按钮,但又想在 onTouched 事件中执行其他操作,例如调用另一个方法,该怎么办?我不能只使用 onPressed 侦听器,因为即使用户没有按下圆形按钮(图像按钮的上角和下角也会触发 onPressed)

所以..有没有办法不必触摸我的实际圆形按钮类的代码来触发 onTouched 事件但运行一些更多代码?..

简单地说.. 我可以为同一个对象设置两个 onTouched 事件,然后决定它们应该“触发”的顺序..

抱歉,这可能有点令人困惑.. 但我讨厌重写我的代码一遍又一遍..

提前致谢!

Now this might be a tricky one :)
The thing is that I whould like to create a library of all my custom components (such as custom buttons, seekbars.. etc etc) for an easier way to implement them in the future..
But the thing is that I have this round button.. which for now extends from the "ImageButton-widget"
Once the button is pressed I use the onTouched-listener to determine if the user actually pressed the round button, and not outside of it..since the ImageButton-widget is "treated" as a "square"..now so far no problems..
But what if I now want to reuse this button but also want to do something else within the onTouched-event, for instance call another method?.. I cant use just the onPressed-listener since that whould also be "triggered" even if the user doesnt press the round button (the upper and lower corners of the imagebutton will trigger onPressed aswell)

So.. is there anyway to without having to touch my code for the actual roundbutton-class to trigger the onTouched-event but run some more code?..

To put it all simple.. can I have two onTouched events for the same object and then decide which order they should "trigger in"..

Sorry this might be kind of confusing.. but I hate to rewrite my code over and over..

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文