2011-05-15 56 views
0

如何將標題爲「位置已保存到文件」的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(); 

回答

0

你可以從一個警告對話框,如果你使用該模式顯示一個警告對話框的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是活動等級。