关闭微调下拉菜单时捕获事件 [英] Catching an event when spinner drop down is dismissed

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

问题描述

我想在微调下拉菜单被关闭时捕捉一个事件.当用户单击 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"

我观察了来源代码,这是从finishInputEvent(InputEvent event,boolean handle)方法中的InputEventReceiver.java打印出来的.但这是一个最终方法,因此没有必要覆盖它.有人可以建议在这些情况下关闭下拉菜单时的处理方式吗?

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?

推荐答案

我使用了 Popup Menu 而不是 Spinner.因为据我所知,微调器无法捕获关闭事件,但是在弹出菜单中,我通过将 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天全站免登陆