Android - ImageView onTouchListener not responding to touches

361 views Asked by At

Situation: I have a BottomSheet that have a button (ImageView) in the upper-right corner to close it manually, when ever I click that button the app crashes (below is the code and the LogCat)

PS: I am working with fragments

JAVA Code

bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            // React to state change
            if (newState == BottomSheetBehavior.STATE_EXPANDED){
                    CloseSheet.setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            if(event.getAction() == MotionEvent.ACTION_DOWN){
                            }
                            else if(event.getAction() == MotionEvent.ACTION_UP){
                                  //This is wher the error happens
                                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);                                    
                            }
                            else if(event.getAction() == MotionEvent.ACTION_CANCEL){
                            }
                            return true;
                        }
                    });
            }else if (newState == BottomSheetBehavior.STATE_DRAGGING){
               bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); 
            }
        }

LogCat

FATAL EXCEPTION: main
Process: com.incorp.labs.appdict, PID: 26159
java.lang.IllegalArgumentException: Illegal state argument: 5
   at android.support.design.widget.BottomSheetBehavior.startSettlingAnimation(BottomSheetBehavior.java:624)
   at android.support.design.widget.BottomSheetBehavior.setState(BottomSheetBehavior.java:548)
0

There are 0 answers