开发者

How do I set the onCancelListener for a search?

开发者 https://www.devze.com 2023-02-16 19:01 出处:网络
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 th

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?


Apparently you should OnDismissListener instead of OnCancelListener because the latter is only invoked for specific events. Using the Android Search Dialog explains this in detail and links to setOnCancelListener and friends.

Note - you only need a Context object to retrieve the SearchManager via getSystemService and call setOnCancelListener:

SearchManager searches =
    (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
searches.setOn{Cancel,Dismiss}Listener( ... );
0

精彩评论

暂无评论...
验证码 换一张
取 消