我有一个Android应用程序,它将喜欢的内容发送到服务器。
我想做的不是立即向服务器发送服务,但如果用户仍然喜欢该帖子,则会在2秒后发送。
我喜欢无效;
For Each o As Object In UltraPanel1.ClientArea.Controls
If TypeOf (o) Is UltraDateTimeEditor Then
Dim datePicker As UltraDateTimeEditor = o
Dim datevalue As Object = datePicker.Value
End If
Next
答案 0 :(得分:1)
使用isReadyToPost
标志:
if(isReadyToPost){
isReadyToPost=false;
}else{
// try after 2 secs for next like
}
并且Handler. postDelayed
在2秒后将isReadyToPost
更改为true:
@Override
public void run() {
isReadyToPost=true;
}
isReadyToPost
默认值为true
。
答案 1 :(得分:0)
您可以尝试创建一个休眠2秒的线程,然后检查用户是否仍然喜欢该帖子,然后更新您的数据库
答案 2 :(得分:0)
尝试这种方法:
boolean isReadyToPost= false;
boolean liked = false;//control like click (witch)
public void onLikePressed() {
if (liked && isReadyToPost) {
sendLikeToServer();//send to server after 2 secs
return;
}
this.isReadyToPost= false;
Toast.makeText(this, "waiting for any dislike... in 2 secs", Toast.LENGTH_SHORT).show();
if (liked){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
isReadyToPost=true;
onLikePressed();
}
}, 2000);
}//end if
} //end onlikepress