image.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
String serverResponse = "";
JSONObject responseToJSON = null;
try {
//if we have Internet connection
if(NetworkRequest.hasNetworkConnection(MyActivity.this)){
//download the server response
serverResponse = NetworkRequest.getUrlData(array.get(i));
responseToJSON = new JSONObject(serverResponse);
String individualDescription = responseToJSON.getString("Description");
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
});
I have the aforementioned code. Where I set an OnClickListener on an image. So, when I will click on the image i override the onTouch method. Then I check if I have internet connection. If I have I try to download a content from the internet. That I want to do is to have something as a Timer and check if the following line of code
我有上面提到的代码。我在图像上设置OnClickListener的位置。所以,当我点击图像时,我会覆盖onTouch方法。然后我检查我是否有互联网连接。如果我有,我尝试从互联网上下载内容。我想做的是将一些东西作为Timer,并检查以下代码行
NetworkRequest.getUrlData(array.get(i))
needs more than 2 seconds to download the content. If needs more that 2 seconds to download the content, I want to cancel both downloading and the OnTouchListener. Is this possible? Any ideas?
下载内容需要2秒以上。如果下载内容需要2秒以上,我想取消下载和OnTouchListener。这可能吗?有任何想法吗?
1 个解决方案
#1
-1
Check this link. Assign to a variable the system time, then check is this time is greater that the last one + 2000 and here you go :-).
检查此链接。将变量分配给变量系统时间,然后检查这个时间是否大于最后一个+ 2000并且在这里你去:-)。
Cheers
#1
-1
Check this link. Assign to a variable the system time, then check is this time is greater that the last one + 2000 and here you go :-).
检查此链接。将变量分配给变量系统时间,然后检查这个时间是否大于最后一个+ 2000并且在这里你去:-)。
Cheers