Kostia Kostia - 4 months ago 17
Android Question

EditText onTouch called more than once

I have an EditText that I attached

onTouchListener
to it:

m_outputField.setOnTouchListener(touchListener);


Now I see that
onTouch
is called 3 times for every actual touch(click):

class MyTouchClickListener implements View.OnTouchListener
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
//do something

return true;
}

}


I guess that I am doing something wrong here, how to fix it (or at least ignore the second and third calls)?

Thanks

Answer

This should fix it:

class MyTouchClickListener implements View.OnTouchListener
{
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        if(event.getAction()==MotionEvent.ACTION_UP)
        {
            //do something
        }
        return true;
    }

}
Comments