我尝试将该方法实现到我的 Button 中onClickListener
,然后我得到了一个Syntax Error
.
下面是我的代码:
// button click event
btnCreateNewEvent.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Checking for server respond
if (serverRespond() == false) {
//DO SOMETHING
}
以下是我的ServerRespond
外部onCreate
方法
// Check server respond
public boolean serverRespond() {
boolean success = false;
try {
URL url = new URL(url_create_event);
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
urlcon.connect();
if (urlcon.getResponseCode() == 200) {
success = true;
}
} catch (Exception e) {
Log.e(create_error.toString(), "Server is not responding");
}
return success;
}
错误:在if(serverRespond()==true){
"The method serverRespond() is undefined for the type new View.OnClickListener(){}"