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

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

问题描述

我想抓住一个事件,当微调下拉被关闭。当用户点击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 processed)方法中的 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?

推荐答案

我已经使用了弹出菜单而不是Spinner。因为根据我的知识,关闭事件不能被微调器捕获,而是使用Popup菜单,通过将 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天全站免登陆