2017-11-04 267 views
12

,當我嘗試添加ontouchListner一個按鈕讓我的Android按鈕setOnTouchListener呼籲,但不會覆蓋performClick

Button has setOnTouchListener called on it but does not override performClick

警告。誰知道怎麼修它。 謝謝你..

1

btnleftclick.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View view, MotionEvent motionEvent) { 
     return false; 
    } 
}); 

錯誤:

Custom view has setOnTouchListener called on it but does not override performClick If a View that overrides onTouchEvent or uses an OnTouchListener does not also implement performClick and call it when clicks are detected, the View may not handle accessibility actions properly. Logic handling the click actions should ideally be placed in View#performClick as some accessibility services invoke performClick when a click action should occur.

+0

請將錯誤消息文本複製並粘貼到您的問題中。 –

+0

自定義視圖'ImageView'對其調用了setOnTouchListener,但不覆蓋performClick 如果覆蓋onTouchEvent或使用OnTouchListener的視圖並未實現performClick並在檢測到點擊時調用它,則視圖可能無法正確處理輔助功能操作。理想情況下,處理點擊操作的邏輯應放置在View#performClick中,因爲某些輔助功能服務會在發生點擊操作時調用performClick。 – kas

+0

如果上述評論是您的錯誤消息,我建議您將其放入問題的文本中。 –

回答

0

您是否嘗試過加入:

view.performClick() 

或添加註釋suppresslint:

@SuppressLint("ClickableViewAccessibility") 

+1

是的。這與Android工作室3.0版的waring comeup – kas

+0

好的,我有一個替代解決這個警告。請參閱: https://stackoverflow.com/questions/47170075/kotlin-ontouchlistener-called-but-it-does-not-override-performclick – lambda

8

解決方案:

  1. 創建擴展按鈕或任何視圖類,你正在使用,並覆蓋performClick()

    class TouchableButton extends Button { 
    
        @Override 
        public boolean performClick() { 
         // do what you want 
         return true; 
        } 
    } 
    
  2. 現在在XML中使用此TouchableButton和/或代碼,警告將消失!

+0

這真的很糟糕。有沒有辦法使用現有的意見? – Milk