安卓onBackDown的返回值

安卓onBackDown的返回值意义

 public boolean onKeyDown(int keyCode, KeyEvent event) {
       if(keyCode==KeyEvent.KEYCODE_BACK&&event.getRepeatCount()==0){
            adapter.notifyDataSetChanged();
           //删除之后,对话框消失
            cancle_Checkbox();
            //取消时隐藏checkbox并把所有选择清空
            for (ItemBean bean : dataList) {
                bean.setChecked(false);
            }
            selectNum=1;
            linearLayout.setVisibility(View.GONE);
            isShow=false;
        }
        if (linearLayout.getVisibility()==View.VISIBLE){
            return false;
        }else return super.onKeyDown(keyCode, event);

       // return super.onKeyDown(keyCode, event);
    }

   if (linearLayout.getVisibility()==View.VISIBLE){
            return false;
        }else return super.onKeyDown(keyCode, event);//

区别在于要不要把这个事件吃掉。返回false是不吃掉,后面的监听也能得到这个事件,而返回true是吃掉,后面的监听就得不到这个事件了(返回不起作用了)。

发布了46 篇原创文章 · 获赞 12 · 访问量 1591

猜你喜欢

转载自blog.csdn.net/weixin_43605701/article/details/103278874