【发布时间】:2013-06-01 16:22:27
【问题描述】:
按下按钮后,应用程序会尝试将数据发送到服务器。如果连接处于活动状态,则立即发送数据,但如果链接断开,系统将尝试发送 x 秒。实际上,在那段时间里,界面(故意)被阻塞(按钮被点亮以突出当前操作)。问题在于,如果用户开始按下其他按钮,则会听到事件,并且当连接变为活动状态时,它会执行与这些事件相关的所有操作。
如何预防?
如何防止这种情况如何防止与其他按钮相关的每个事件被处理?
任何建议将不胜感激。
编辑 我已经尝试在按下按钮时检查标志,不幸的是,当重新设置标志时,所有事件都被捕获并执行:
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;
}
}
在其他按钮监听器上:
谢谢
【问题讨论】:
标签: android events button event-handling