捕获事件时微调下拉被驳回 [英] Catching an event when spinner drop down is dismissed

查看:185
本文介绍了捕获事件时微调下拉被驳回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要赶事件时微调下拉被驳回。当用户点击任何项目在onItemSelected我们可以捕捉它()。但我想,即使用户触摸下拉区域或后退按钮,因为这些之外也使其消失赶上。在我观察到的日志这两个原因,它说的试图完成一个输入事件,但输入事件接收器已被释放

I want to catch an event when spinner drop down is dismissed. We can catch it when the user clicks on any item in the onItemSelected(). But I want to catch even when user touches outside of the drop down area or back button as these too make it disappear. In these two causes when I observed log, it says "Attempted to finish an input event, but the input event receiver has already been disposed"

我观察到的<一个href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/InputEventReceiver.java">source code ,这是从印刷在 InputEventReceiver.java finishInputEvent(InputEvent的情况下,布尔处理)方式。但是,这是一个最终的方法,所以没有点覆盖它。可有一个人请建议的方法来处理时,下拉被驳回在这种情况下?

I observed the source code, this is printed from the InputEventReceiver.java in the finishInputEvent(InputEvent event, boolean handled) method. But it's a final method, so there is no point of overriding it. Can some one please suggest the way to handle when the drop down is dismissed in those cases?

推荐答案

我已经使用弹出菜单而不是微调。因为据我所知,辞退事件可能不会被抓与微调,但与弹出菜单我通过设置做到了 onDismissListerner()的弹出式菜单

I have used Popup Menu instead of Spinner. Because as far as my knowledge, dismiss event couldn't be caught with spinner, but with Popup menu I did it by setting onDismissListerner() to the popup menu

popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {  
             public boolean onMenuItemClick(MenuItem item) {  
              Toast.makeText(MyActivity.this,"Clicked on: " + item.getTitle(),Toast.LENGTH_LONG).show();  
              return true;  
             }  
            });  
popup.setOnDismissListener (new PopupMenu.OnDismissListener(){

public void onDismiss()
{
   //catch dismiss event here.
}
});

这篇关于捕获事件时微调下拉被驳回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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