Android Studio View.OnTouchListener错误消息:如何添加performClick?

时间:2018-11-13 01:42:45

标签: android ontouchlistener

我有一个带有OnTouchListener的ListenerEditText,目的是在用户触摸EditText行时向他们显示一个键盘。 Android Studio显示警告“ CustomView'ListenerEditText'已调用setOnTouchListener,但未覆盖performClick”。

我试图添加performClick()以实现可访问性,但这并不能消除警告。我将v.performClick()添加到了代码中,并将MotionEvent.ACTION_UP添加为建议的可能重复答案,但它并没有删除棉绒警告。我在这里想念什么?

cListenerEditText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Configuration config = getResources().getConfiguration();
            if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
                v.requestFocusFromTouch();
            } else {
                v.requestFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                performClick();
            }
            return false;
        }

        // Studio gives a warning here "Method does not override method from its superclass"
        @Override
        public boolean performClick() {
            // Calls the super implementation, which generates an AccessibilityEvent
            // and calls the onClick() listener on the view, if any
            // Studio says 'Cannot resolve method performClick()'
            super.performClick();

            // Handle the action for the custom click here

            return true;
        }

    });    

0 个答案:

没有答案