Android: как показать диалоговое окно после того, как пользователь нажимает «Хорошо» в предыдущем диалоговом окне - PullRequest
0 голосов
/ 16 мая 2011

Почему AlertDialog с названием «Местоположение было сохранено в файл» не отображается? Это тот, который должен отображаться после того, как пользователь нажмет 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();

1 Ответ

0 голосов
/ 16 мая 2011

Вы МОЖЕТЕ отобразить диалоговое окно предупреждения из диалогового окна предупреждения, если вы используете шаблон 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.ИЛИ вы можете просто поднять тост, как в:

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

, где Main - класс активности.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...