将自定义视图放到窗口管理器上时,OnClickListener无法在服务内部工作

时间:2015-08-13 18:44:44

标签: android events click

美好的一天。我按照教程创建Facebook通知(将视图扩展到android的主屏幕上)并且我确实成功实现了,除了onClickListener事件之外,一切正常。我正确地找到2个按钮的视图但仍然在我在onClickListener上设置它们都没有发生任何事情!这是我的代码

 client.getCallClient().addCallClientListener(new CallClientListener() {
        @Override
        public void onIncomingCall(CallClient callClient, final Call call) {
            LayoutInflater li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    //WindowManager.LayoutParams.TYPE_INPUT_METHOD |
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,// | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.RIGHT | Gravity.TOP;
            final View myview = li.inflate(R.layout.pick_up_call, null);
            wm.addView(myview, params);
            acceptcall = (Button) myview.findViewById(R.id.button2);
            hangupcall = (Button) myview.findViewById(R.id.button3);
            acceptcall.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    Log.d("asfhkajsfa","clicked accept");
                    call.answer();
                    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
                    KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
                    lock.reenableKeyguard();
                    return false;
                }
            });
            hangupcall.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    call.hangup();
                    wm.removeView(myview);
                    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
                    KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
                    lock.disableKeyguard();
                    return false;
                }
            });
        }
    });
}

它非常简单,没有什么特别的,但onClick事件不会触发NO WAY。非常感谢你事先!

编辑:我刚将onClickListener更改为onTouchListener但仍然失败,也没有触发!

0 个答案:

没有答案