0

In my application, i have set OnTouchListener and OnClickListener to an ImageView. Problem is when i click an ImageView both OnTouchListener and OnClickListener are working. But i want to avoid the OnTouchListener when clicked on image, and when dragging the ImageView OnTouchListener should work and OnClickListener should be avoided. Any suggestions...

Below is my code:

imageview.setOnClickListener(m_onClickListner);
imageview.setOnTouchListener(this);

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {

    }else if (event.getAction() == MotionEvent.ACTION_MOVE) {

    }
    if (event.getAction() == MotionEvent.ACTION_UP) {

    }
    return true;
}

OnClickListener m_onClickListner = new View.OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    };
Vamshi
  • 1,495
  • 1
  • 15
  • 31
  • see my edit, code is also posted... – Vamshi Mar 06 '14 at 11:14
  • you may use Button.setEnabled(false); for not clicking – user2609847 Mar 06 '14 at 11:18
  • This is already answered here: http://stackoverflow.com/questions/14480418/receiving-ontouch-and-onclick-events-with-android – Jehy Mar 06 '14 at 11:20
  • there no answer in that link and also if i use only on touch every time it is calling MotionEvent.ACTION_DOWN...but in that i am creating new imageview for dragging, so for click of an event also it is creating new image.. i don't want to use action_down when clicking of an imageview – Vamshi Mar 06 '14 at 11:29

1 Answers1

0

i that case you should use setOnLongClickListener for dragging.

imageview.setOnLongClickListener(new OnLongClickListener()
{
    @Override
    public boolean onLongClick(View v)
    {
        // TODO Auto-generated method stub
        return false;
    }
});
Mr. Borad
  • 391
  • 2
  • 24
  • how to calculate the x,y positions of the view using onlongclick, i am using 2.2 api and i am calculating the x,y positions using ontouch motionevent... – Vamshi Mar 06 '14 at 12:27
  • yes that's right you cant get MotionEvent on it. is there just ImageView or list are you useing ? – Mr. Borad Mar 06 '14 at 12:36