将点击侦听器添加到整个应用程序小部件
我有一个 appwidget,我想在整个 appwidget 布局上添加一个单击侦听器,而不仅仅是在 TextView ecc 上。 这不起作用
remoteViews.setOnClickPendingIntent(R.layout.profile_widget_layout, pendingIntent);
我该怎么办?
I have an appwidget and I want to add a click listener on the entire appwidget layout, not only on TextView ecc.
This is not working
remoteViews.setOnClickPendingIntent(R.layout.profile_widget_layout, pendingIntent);
How can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能将
setOnClickPendingIntent()
与布局资源 ID 一起使用,只能与小部件 ID 一起使用。您需要做的就是为最外层容器分配一个
android:id
属性(例如RelativeLayout
),然后使用setOnClickPendingIntent()
与该属性android:id
值。You cannot use
setOnClickPendingIntent()
with a layout resource ID, only with a widget ID.All you need to do is assign an
android:id
attribute to your outermost container (e.g.,RelativeLayout
), then usesetOnClickPendingIntent()
with thatandroid:id
value.这可能不再是正确的,因为过去几天我一直在绞尽脑汁地思考为什么当我试图设定意图时它对我不起作用在我的小部件的主relativelayout(R.id.TheEntireWidget)上。 (是的,可点击属性设置为 true。)
当我开始将其应用于可见绘图时,功能!
我怀疑这可能已被更改以处理透明的某物或其他可能拦截触摸的情况。我的小部件没有背景或任何其他可见的分配给顶级相对布局。
This may no longer be quite true, as I've spent the last few days scratching my head about why it did not work for me when I was trying to set the intent on the master RelativeLayout (R.id.TheEntireWidget) for my widget. (Yes, the clickable attribute was set to true.)
The moment I started applying this to visible drawables, functionality!
I suspect this may have been changed to deal with a transparent something-or-otehr possibly intercepting touches. My widget has no background or anything otherwise visible assigned to the top-level RelativeLayout.