按下按钮时,应用程序会尝试将数据发送到服务器。如果连接处于活动状态,则会立即发送数据,但如果链路断开,系统会尝试发送x秒。事实上,在这段时间内,界面被(有意)阻塞(按钮点亮以突出显示当前操作)。问题是,如果用户开始按下其他按钮,则会听到事件,并在连接变为活动状态时执行与这些事件相关的所有操作。
我该如何预防?
如何防止如何防止与其他按钮相关的每个事件被处理? 任何建议将不胜感激。Android:单击按钮后丢弃的事件
编辑 我已经尝试过检查按下按钮时,不幸的是,当该标志重新设置好的,所有事件都被获取,并执行一个标志:
public void onClick(View v) {
switch(v.getId())
{
case R.id.button1: //when sendData() is trying to send the message, I don't want to that this code is executed
if(flagConf == 1)
{
...do something...
}
break;
case R.id.buttonConfirm:
if(myFlag == 1) //to avoid multiple touch of this button
{
...do something...
myFlag = 0;
sendData();
if(dataSent)
...do something...
else
...do something...
myFlag = 1; //I set this flag to 1 because, if message is not sent, the user have to re-pressed the buttonConfirm and try again
}
break;
}
}
以及其他按钮听众:
感谢
不幸的是,我已经这样做了,但所有其他事件都被捕获了......当连接打开时,所有事件都被处理。 – Ant4res
嗯......除非你的代码中还有别的东西出现,否则这是毫无意义的。你已经在'onClick'中试过了上面的代码,代码仍然运行?如果是这种情况,那么你可能想要发布一些代码,所以我们可以看到究竟发生了什么 – codeMagic
我编辑了我的问题,谢谢。 – Ant4res