使用单击侦听器在EditText中单击和双击 [英] Single Click and Double Click in EditText using the click listener
本文介绍了使用单击侦听器在EditText中单击和双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的要求是,单击编辑文本"时,用户可以输入数据,双击则可以显示所有数据的活动.
My requirement is, on single click on Edit Text, user can enter data, on double click go to an activity where all data will be present.
我使用了再次按下退出的逻辑,但我无法实现.
I used the logic for press again to exit, I am unable to achieve it.
ETBarCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
doublePress=doubleTap();
if(doublePress) {
ETBarCode.requestFocus();
InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(ETBarCode.getWindowToken(), 0);
}
else
{
Toast.makeText(MoveActivity.this, "Enter Data", Toast.LENGTH_SHORT).show();
ETBarCode.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(ETBarCode, 0);
}
}
});
}
private boolean doubleTap()
{
if (doubleBackToExitPressedOnce) {
Toast.makeText(this, "Scanning", Toast.LENGTH_SHORT).show();
return doubleBackToExitPressedOnce;
}
this.doubleBackToExitPressedOnce = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
return doubleBackToExitPressedOnce;
}
有什么办法可以解决吗?
Is there any way to sort it out?
推荐答案
使用GestureDetector
检测:
final GestureDetector gestureDetector = new GestureDetector(your_context,new GestureDetector.SimpleOnGestureListener() {
public boolean onDoubleTap(MotionEvent e) {
// start activity
return true;
}
});
EditText et = (EditText) findViewById(R.id.your_id);
et.setOnTouchListener(new View.OnClickListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
这篇关于使用单击侦听器在EditText中单击和双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文