不甘的EditText onTouchListener函数调用 [英] Unwilling EditText onTouchListener Function Call

查看:145
本文介绍了不甘的EditText onTouchListener函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  公共布尔onKey()调用两次?

我有一个EditText字段,它要求具有单选按钮的弹出视图。弹出窗口并RadioGroup中实现工作不错。但我只是知道,当pressed或触摸到的EditText,onTouchListener被称为2倍。我也只是意识到,我的 previous问题的道理是一样的问题。 这里是在EditText上;

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;
            }
        }); 

和这里是XML进行的EditText

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.

推荐答案

双呼叫因为触摸监听器闪光两次(至少!),一旦当上的EditText(ACTION_DOWN)手指的土地,一旦当你解除手指(ACTION_UP)。为了解决这个问题,只要确保你只能激活一种情况。或者,你可以只设置一个的onClick 监听器代替。

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;
      }

这篇关于不甘的EditText onTouchListener函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆