ユーザーが入力した電子メールIDが一意であるかどうかをチェックしたいのですが、最初は変数がBoolean valid = false;
です。ボタンをクリックすると、入力された電子メールIDを取得し、正規表現を使用して有効な電子メールIDの式をチェックしています。次に、一意性をチェックするためにasyntaskを使用しています。私onclicklistnerのコードは、ここで私が直面していますどのような問題プログラムがAndroid Studioの正しい順序で実行されていない
if (emailid.matches(regexp) && emailid.length() > 0) { new Validate().execute(); Toast.makeText(getApplicationContext(), valid.toString(), Toast.LENGTH_LONG).show(); if (valid) { data.putString("eid", eid); data.putString("firstname", firstname); data.putString("lastname", lastname); data.putString("emailid", emailid); Intent i = new Intent(getApplicationContext(), GamesFragment.class); startActivity(i); } else { Toast.makeText(getApplicationContext(), "Email Address Already Exist", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(getApplicationContext(), "Check Your Email Address", Toast.LENGTH_LONG).show(); }
である私は独特であり、ボタン、Validate()
asynctaskチェックをクリックするとtrueにvalid
変数を設定し、電子メールを入力していたときに初めて、あります私はvalid = false
を最初に宣言しているので、次のアクティビティGamesFragment
には向かない。ここでもう一度ボタンをクリックすると、前のクリックのためにvalid
変数がtrueに設定されているため、次のアクティビティに移動します。 今私Validate()
asynctaskは、なぜこれが起こっている私は得ていないのです助けてください
private class Validate extends AsyncTask<Void, Void, Void> {
@Override
protected Boolean doInBackground(Void... params) {
ArrayList<NameValuePair> emailId = new ArrayList<NameValuePair>();
emailId.add(new BasicNameValuePair("email", emailid));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("url/validate.php");
httppost.setEntity(new UrlEncodedFormEntity(emailId));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
iss = entity.getContent();
} catch(Exception e) {
Log.e("pass 1", "Connection Error");
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader
(new InputStreamReader(iss,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
sb.append(line + "\n");
iss.close();
result = sb.toString();
} catch(Exception e) {
e.printStackTrace();
}
try {
JSONObject json_data = new JSONObject(result);
code=(json_data.getInt("code"));
if(code == 1)
valid = true;
else
valid = false;
Log.e("pass 3", "valid "+valid);
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
}
です。
検証は、あなたの同じクラスの右にありますか? @AdnanMomin – KDeogharkar
yes @KDeogharkar – knownUnknown
validateはmy ** inner class ** – knownUnknown