How to correctly handle click events on Widget

心不动则不痛 提交于 2019-12-07 04:18:59

问题


There is a task to make smt like todo list on widget (with dynamic number of elements), how to organize this list for click support on this elements. I only found how add click event on one widget layout element (with setOnClickPendingIntent), and how send text to widget element TextView.

But it's unclear how handle click events for sub-elements, or how get click coordinates(or item) where was click event. I saw widget "Agenda widget" - and it work fine with clicking on different calendar rows.

I will be very much appreciated for help.


回答1:


But it's unclear how handle click events for sub-elemets

Use setOnClickPendingIntent().

or how get click coordinates(or item) where was click event

Use different Intents inside of the PendingIntents passed to setOnClickPendingIntent(). By "different", you need something other than an extra to be different, such as a distinct action string.



来源:https://stackoverflow.com/questions/2797947/how-to-correctly-handle-click-events-on-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!