可能重复: 公共布尔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;
}