Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwilling EditText onTouchListener Function Call [duplicate]

Possible Duplicate:
public boolean onKey() called twice?

I have an EditText field which calls a popUp view with radio buttons. PopUp and RadioGroup implementation works nice. But I just realize when pressed or Touch to EditText, onTouchListener is called 2 times. I also just realize that the reason of my previous question is the same issue. Here is the the EditText;

etOdemeSekli = (EditText)findViewById(R.id.etOdemeSekli);
        etOdemeSekli.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                inflatePopUpOdemeSekli();
                Log.d("****","Inflate");                    
            return false;
            }
        }); 

and here is the xml for EditText

<EditText
    android:layout_weight="1"                   
    android:id="@+id/etOdemeSekli"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/odemeSekliHint"
    android:focusableInTouchMode="false">
</EditText>

Because of this double call, popup acts weird. The dismiss() call does not function properly. What could be the reason? It is really really annoying, thank you.

like image 721
tan Avatar asked Dec 16 '22 00:12

tan


1 Answers

The double call is because the touch listener fires twice (at least!), once for when the finger lands on the EditText (ACTION_DOWN) and once when you lift the finger (ACTION_UP). To fix it, just make sure you only activate on one case. Alternatively, you could just set an onClick listener instead.

      public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
              inflatePopUpOdemeSekli();
            }

            return false;
      }
like image 163
dmon Avatar answered May 01 '23 10:05

dmon