Note that there are some explanatory texts on larger screens.

plurals
  1. POAlertDialog Button needs double click
    primarykey
    data
    text
    <p>I am showing the progress dialog for downloading the file in my application, but if in case the user needs to cancel the download, then he will have to press the back button and then it will pop up alert dialog with two buttons. The problem is that I have to double click the alert dialog's buttons, and then only the alert dialog is dismissed. suggest me any solution for it.</p> <p>here is peace of code for your reference..</p> <pre><code>@Override protected Dialog onCreateDialog(int id) { switch (id) { case progress_bar_type: pDialog = new ProgressDialog(this); pDialog.setMessage("Downloading file. Please wait..."); pDialog.setIndeterminate(false); pDialog.setMax(100); pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pDialog.setCancelable(true); pDialog.show(); pDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if(keyCode == KeyEvent.KEYCODE_BACK){ running = false; /*Intent intent = new Intent(context, NewDialog.class); startActivity(intent);*/ AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); alertDialog.setIcon(R.drawable.ic_launcher); alertDialog.setTitle("Ariisto"); alertDialog.setMessage("Do you Want to Cancel the Download ?"); alertDialog.setCancelable(true); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { File externalFile = new File(Environment.getExternalStorageDirectory(),"downloadedfile.pdf"); externalFile.delete(); pDialog.dismiss(); running = false; Log.d("External File", "DELETED"); pDialog.setProgress(0); count = 2; } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub new DownloadFileFromURL().execute(file_url); running = true; count = 0; } }); AlertDialog alert = alertDialog.create(); alert.show(); } return false; } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload