在 Activity 上调用的片段内的 onClick [英] onClick inside fragment called on Activity

查看:24
本文介绍了在 Activity 上调用的片段内的 onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将内容封装到一个片段中,但遇到了一个很难用谷歌搜索的问题.在我的片段中是一些具有 onClick 属性的按钮,但它们是在 Activity 上调用的,而不是来自 android 系统的片段 - 这使得封装有点笨拙.有没有办法让 onClick 的反射内容调用片段?我目前看到的唯一解决方案是不要在 xml 中使用 onClick 并通过代码在片段内设置点击侦听器.

i am encapsulating stuff into a fragment at the moment and run into a problem that is hard to google. Inside my fragment are some buttons with onClick attributes but they are called on the Activity rather the fragment from the android system - this makes encapsulating a bit clumsy. Is there a way to have the reflection stuff from onClick to call on the fragment? The only solution to this I see at the moment is not to use onClick in the xml and set click-listeners inside the fragment via code.

推荐答案

我与一些 googlers @ #adl2011 进行了交谈 - 他们认识到了这个问题,也许将来会解决这个问题.在那之前 - 应该在 Fragment 中使用 .setOnClick.

I spoke to some googlers @ #adl2011 - they recognize the problem and perhaps there will be a fix of that in the future. Until then - one should use .setOnClick in the Fragment.

这篇关于在 Activity 上调用的片段内的 onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆