如何设置搜索的 onCancelListener?
我正在实现一个具有搜索功能的 MapView,并且必须执行一些特定操作才能使搜索正常工作(IE 打开搜索将查询的图标层)。我当前正在使用 OnSearchRequested
方法来执行这些操作。但是,如果用户取消搜索对话框,我想将地图返回到之前的状态(即按搜索键之前的状态)。
我在文档中读到可以使用 OnCancelListener
来执行此操作,但是我不确定如何将其添加到搜索功能中。据我所知,通过创建一个简单的对话框,您只需输入 dialog.setOnCanelListenr(myListener)
即可。但是,由于搜索视图不受我的 mapView
控制,我该如何设置呢?有可能吗?
I'm implementing a MapView
with a search feature, and have to perform some specific actions for the search to work well (I.E. turn on the layer of icons the search will query). I'm currently using the OnSearchRequested
method to perform these actions. However, if the user cancels out of the search dialog, I want to return the map to its former state (that is, the state prior to pressing the search key).
I read in the documentation where it's possible to do this using an OnCancelListener
, however I'm unsure how to add this to the search feature. I understand that with a simple dialog you're creating you can just say dialog.setOnCanelListenr(myListener)
. However, since the search view is not being controlled by my mapView
, how would I set this? Is it even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然您应该使用使用 Android 搜索对话框 详细解释了这一点,并链接到OnDismissListener
而不是OnCancelListener
,因为后者仅针对特定事件调用。setOnCancelListener
和朋友。注意 - 您只需要一个
Context
对象即可通过 getSystemService 并调用setOnCancelListener
:Apparently you shouldUsing the Android Search Dialog explains this in detail and links toOnDismissListener
instead ofOnCancelListener
because the latter is only invoked for specific events.setOnCancelListener
and friends.Note - you only need a
Context
object to retrieve theSearchManager
via getSystemService and callsetOnCancelListener
: