Can't handle both click and touch events simultaneously

后端 未结 12 2032
时光说笑
时光说笑 2020-12-01 03:45

I am trying to handle touch events and click events on a button. I do the following:

button.setOnClickListener(clickListener);
button.setOnTouchListener(touc         


        
12条回答
  •  無奈伤痛
    2020-12-01 04:00

    button.setOnTouchListener(this);
    

    Implement interface and the code here:

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        switch (view.getId()) {
            case R.id.send:
                switch(motionEvent.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        //when the user has pressed the button
                        //do the needful here
                        break;
                    case MotionEvent.ACTION_UP:
                        //when the user releases the button
                        //do the needful here
                        break;
                }
                break;
        }
        return false;
    }
    

提交回复
热议问题