У меня есть два варианта ввода данных. Если пользователь вводит данные, он автоматически отображает диалоговое окно при изменении фокуса и исчезает при любом ответе. Но если я вызываю тот же метод при последней кнопке, нажмите, чтобы проверить, редактируется ли текстовое значение, установленное с сервера, является правильным или нет. Мой Progressdialog продолжается до тех пор, пока я не щелкну или не коснусь где-нибудь на экране, оно не скрывается автоматически, когда я получаю ответ от сервера.
Вот мой код
i have defined all the edittext values and strings as per my need
// on create
farmer_edit = findViewById(R.id.farmer_edit);
farmer_edit.setText(cdpFarmerGeneralMain.getCDPFarmerGeneral().getFarmerName());
//here Farmer Edit_ is the edittext name of the farmer and in set text if i am getting any value from server then setting it to edittext
//now i want to check the name from sevre if its correct or not
// in this case i am assuming that user is manually entering his/her name by using on Focus change
farmer_edit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
farmer_name = farmer_edit.getText().toString();
aadhaar_api();
//here Aadhaar_api is my method in which i am checking name from server
}
}
});
//I have Created a seprate method to check if my edit text is empty on button click if yes show error
private boolean validate_farmer_name() {
farmer_name = farmer_edit.getText().toString();
if (farmer_name.equals("")) {
farmer_edit.requestFocus();
farmer_edit.startAnimation(shakeError());
farmer_edit.setError("Enter Name ");
return false;
}
return true;
}
private void checking_all_data() {
if (!validate_farmer_name()) {
return;
}
// I am trying to check name again from here if its enterd from server.
//after using this my dialog is in continuous Running State
aadhaar_api();
Toast.makeText(this, "Next Work to done if Name matches to our server",Toast.LENGTH_SHORT).show();
}
// here is the method which show dialog box
private void aadhaar_api() {
String url = "here is our url";
Log.i("Regist_aadhar_url", url);
dialog = "Checking Name With Aadhaar Card";
showDialog();
VolleyLog.DEBUG = true;
RequestQueue queue = SingletonRequestQueue.getInstance(getApplicationContext()).getRequestQueue();
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Log.i("respon_print ", response.toString());
JSONObject json = new JSONObject(response);
int success = json.getInt("success");
String msg = json.getString("message");
if (success == 0) {
hideDialog();
farmer_edit.setError("Farmer Name not Matched with Aadhaar Card");
farmer_edit.setText("");
farmer_edit.requestFocus();
farmer_name = "";
Log.i("response_work_0", response.toString());
}
if (success == 1) {
// hideDialog(); tried stoping here but nothing happened
account_name_edit.setText(farmer_name);
account_holder_name = farmer_name;
bol = true;
Log.i("boolean", String.valueOf(bol));
}
} catch (JSONException e) {
e.printStackTrace();
}
hideDialog();
}
}, errorListener) {
@Override
public Priority getPriority() {
return Priority.HIGH;
}
};
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(stringRequest);
}
private void showDialog() {
pDialog = new ProgressDialog(this);
pDialog.setMessage(dialog);
pDialog.show();
}
private void hideDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}