Hier lassen Sie mich erklären, mein Problem muss volley innerhalb alertdialog hinzufügen, die ich erfolgreich getan habe wie pinging die eingegebene Url es funktioniert gut, aber was ich tun muss, ist in onErrorResponse Methode Alarmdialog wird ausblenden annehmen, wenn Benutzer falsche URL eingeben wird es Geh zu onErrorResponse Methode in das mein Alertdialog verbergen bekommt wach bleiben müssen den Dialog, auch wenn Fehler bisher aufgetreten wird, was ich versucht habe, ist:Wie Salve innerhalb Alarmdialog verwenden?
Dies ist mein Code:
final AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Add Self Hosted URL "); //Set Alert dialog title here
alert.setMessage("Enter The Url Here"); //Message here
final EditText input = new EditText(context);
alert.setView(input);
ConnectivityManager cn = (ConnectivityManager) PingingActivity.this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nf = cn.getActiveNetworkInfo();
if (nf != null && nf.isConnected()) {
final ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.hide();
Toast.makeText(getApplicationContext(), "Network Available", Toast.LENGTH_LONG).show();
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
progressDialog.show();
progressDialog.setMessage("Pinging Please Wait");
final String srt = input.getEditableText().toString();
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.GET, srt,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("resp", response);
SharedPreferences settings = getSharedPreferences(PingingActivity.id, 0); // 0 - for private mode
SharedPreferences.Editor editor = settings.edit();
editor.putString("Url", srt);
editor.putBoolean("URLflag", true);
editor.apply();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// alert.show();
// input.setText(srt);
//final String srt = input.getEditableText().toString();
String str = error.toString();
if (str != null) {
Toast.makeText(getApplicationContext(), "Please Check the Entered URL", Toast.LENGTH_SHORT).show();
// progressDialog.cancel();
}
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
stringRequest.setRetryPolicy(new DefaultRetryPolicy(5000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Toast.makeText(context, srt, Toast.LENGTH_LONG).show();
}
});
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
}).setIcon(R.drawable.ic_info_black_24dp).show(); //End of alert.setNegativeButton
/* Alert Dialog Code End*/
}
else {
showAlertDialog("No Network", "Please Check Your Network Connectivity", true);
}
auch in onerrorresponse Notwendigkeit, zeige meinen alertdialog an, wie ich das erreichen kann. Es kann dumme Frage, aber als Anfänger mit diesem habe Schwierigkeiten kann jeden helpme
Dies liegt daran, dass Ihre Anfrage über einen OK-Klick auf den Alarm erfolgt. – Anurag
Dann was soll ich tun –