Android :: OnTouchListener && OnClickListener combination issue

前端 未结 3 684
慢半拍i
慢半拍i 2020-12-18 07:34

Problem description:

I have a TextView on a RelativeLayout and I want to color it red when the user touches it, and go on another page whe

3条回答
  •  不知归路
    2020-12-18 08:26

    you may call View.performClick() when action_up. Hope it helps.

    your_txtView.setOnClickListener(new TextView.OnClickListener(){
            public void onClick(View v) {
                // TODO Auto-generated method stub
    
            }
        });
    
        your_txtView.setOnTouchListener(new TextView.OnTouchListener(){
                @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (MotionEvent.ACTION_DOWN == event.getAction()) {
    
            } else if (MotionEvent.ACTION_UP == event.getAction()) {
                v.performClick();
            }
    
            return true;
        }
        });
    

提交回复
热议问题