Android:在用户点击前一个对话框中的“Okay”之后如何显示对话框

问题描述:

如何将标题为“位置已保存到文件”的AlertDialog不显示?它是在用户在第一个对话框上按下Ok之后应该显示的那个。Android:在用户点击前一个对话框中的“Okay”之后如何显示对话框

我认为它与线程有关,但我不确定。

 SimpleDateFormat timeStampFormat = new SimpleDateFormat("MMMMM-dd-yyyy"); 


     final EditText input = new EditText(EncounterActivity.this); 
     input.setWidth(75); 
     input.setText("Bear-Encounter-GPS-" + timeStampFormat.format(new Date()) + ".txt"); 

     new AlertDialog.Builder(EncounterActivity.this) 
     .setTitle("Save GPS Location") 
     .setMessage("Please enter a filename") 
     .setView(input) 
     .setIcon(R.drawable.gps) 
     .setPositiveButton("Save", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int whichButton) { 
       try { 
        File root = Environment.getExternalStorageDirectory(); 
        if (root.canWrite()){ 
         File fn = new File(root, input.getText().toString()); 
         FileWriter gpxwriter = new FileWriter(fn); 
         BufferedWriter out = new BufferedWriter(gpxwriter); 
         out.write(ll.toUTMRef().toString()); 
         out.close(); 



         AlertDialog.Builder builder = new AlertDialog.Builder(EncounterActivity.this); 
         builder.setIcon(R.drawable.gps); 
         builder.setTitle("Location was saved to file"); 
         builder.setMessage("Your GPS coordinates were saved to " + fn.getAbsolutePath()) 
           .setPositiveButton("Okay", new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int id) { 

            } 
           }); 
         AlertDialog alert = builder.create(); 
         alert.show(); 

        } 
       } catch (IOException e) { 
        //ProfitBandit.alert(Shipment.this, "Couldn't write the file."); 
        Log.v("IOException", "Could not write file " + e.getMessage()); 
       } 
      } 
     }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int whichButton) { 
       // Do nothing. 
      } 
     }).show(); 

你可以从一个警告对话框,如果你使用该模式显示一个警告对话框的ShowDialog(INT)getInstanceSomeDialog和onCreateDialog(int)的两个对话框。所以在我aboutAlertDialog我有:

builder.setPositiveButton("View EULA", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int id) {    //cancels itself? 
     showDialog(DIALOG_EULA_SHOW); 
    }  
}); 

然后在另一个AlertDialog中显示一个EULA。或者你也可以抛开Toast:

Toast.makeText(Main.this,"Location Saved.", Toast.LENGTH_SHORT).show(); 

其中Main是活动等级。