onInterceptTouchEvent 禁用 ACTION_DOWN/MOVE/UP
我编写了一个程序,它执行这样的任务
0 1 2 3 4
5 6 7 8 9
假设这些是我的布局中的视图。现在假设用户触摸了(按下事件)1,某个字符串被设置为“1 down”。但是当用户滑动到 2 而不释放键 1 上的手指时,它应该将字符串设置为“2 down”,但字符串仍然是“1 down”..我不知道如何实现这一点。它可能必须在 ACTION_MOVE 事件为 1 时完成。但我不知道该怎么做,以禁用其进一步的事件(向上事件)。整个滑动结束后,当我释放按键时,字符串设置为“1 up”。因此它无法识别 2 3 4 等的向下运动事件。它停留在向下模式。我认为可以这样做 onInterceptTouchEvent,但我没有正确获取它。下面是我的源代码。分享你对它的看法。如果可能的话,给我一些关于如何将它合并到我的代码中的示例代码
@Override 公共无效onCreate(捆绑保存实例状态) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// select_btn = (Button) findViewById(R.id.ok);
// home_btn = (Button) findViewById(R.id.home);
et = (EditText) findViewById(R.id.entry);
et.setText("", TextView.BufferType.EDITABLE);
b = new Bundle();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i = 0; i < mybtn.length; i++) {
String btnid = "btn" + i;
int resid = getResources().getIdentifier(btnid, "id",
getPackageName());
mybtn[i] = (Button) findViewById(resid);
mybtn[i].setOnTouchListener(this);
}
} 。
i have coded a program which which does a task like this
0 1 2 3 4
5 6 7 8 9
suppose these are the views in my layout. Now suppose user has touched (down event) on 1,some string is set to "1 down". but when the user slides to 2 without releasing his finger on key 1 , then it should set the string to "2 down", but the string is still "1 down".. i am not getting how to make this possible .it may have to be done on ACTION_MOVE event of 1 . but i am not getting what to do ,to disable its further events (Up event). after the entire sliding when i release the key the string is set to "1 up". so it is not recognizing the motion down events of 2 3 4 etc. it is staying in down mode. i think it could be done with
onInterceptTouchEvent, but i did not get it correctly .below is my source code. share ur views on it.if possible give me some sample code on how to incorporate it into my code
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// select_btn = (Button) findViewById(R.id.ok);
// home_btn = (Button) findViewById(R.id.home);
et = (EditText) findViewById(R.id.entry);
et.setText("", TextView.BufferType.EDITABLE);
b = new Bundle();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i = 0; i < mybtn.length; i++) {
String btnid = "btn" + i;
int resid = getResources().getIdentifier(btnid, "id",
getPackageName());
mybtn[i] = (Button) findViewById(resid);
mybtn[i].setOnTouchListener(this);
}
}
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
移动“int current = 0;”脱离 onTouch 方法。
每当屏幕上有移动时就会调用它,并将 0 放入 current 中。
顺便说一句,我看到你使用了我的代码(其中一部分):
Android 中的运动事件捕获
您至少可以做的是接受答案或将其标记为有用
Move "int current = 0;" out of onTouch method.
It is being called any time there's a movement on the screen and put 0 in current.
by the way, I see you used my code (part of it):
Motion Event Capturing in android
the least you can do is to accept the answer or mark it as useful