Example usage for android.app AlertDialog findViewById

List of usage examples for android.app AlertDialog findViewById

Introduction

In this page you can find the example usage for android.app AlertDialog findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:com.prof.youtubeparser.example.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.action_settings) {

        android.support.v7.app.AlertDialog alertDialog = new android.support.v7.app.AlertDialog.Builder(
                MainActivity.this).create();
        alertDialog.setTitle(R.string.app_name);
        alertDialog.setMessage(Html.fromHtml(MainActivity.this.getString(R.string.info_text)
                + " <a href='http://github.com/prof18/YoutubeParser'>GitHub.</a>"
                + MainActivity.this.getString(R.string.author)));
        alertDialog.setButton(android.support.v7.app.AlertDialog.BUTTON_NEUTRAL, "OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }/*from   w ww  .jav a2 s. co  m*/
                });
        alertDialog.show();
        ((TextView) alertDialog.findViewById(android.R.id.message))
                .setMovementMethod(LinkMovementMethod.getInstance());
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java

private void prepareExportKeysDialog(final Dialog dialog) {
    final AlertDialog alertDialog = (AlertDialog) dialog;

    final EditText passwordView = (EditText) alertDialog.findViewById(R.id.export_keys_dialog_password);
    passwordView.setText(null);//  www . ja v  a2  s  . c o m

    final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(
            passwordView, alertDialog);
    passwordView.addTextChangedListener(dialogButtonEnabler);

    final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.export_keys_dialog_show);
    showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView));
}

From source file:com.fitme.MainActivity.java

public void onTrainingEditRequested(final TrainingRow oldTrain, final TrainingsListAdapter tla) {
    final Activity activity = MainActivity.this;
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(getString(R.string.title_upd_training_dialog));
    builder.setView(getLayoutInflater().inflate(R.layout.dialog_add_training, null));
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog trainDialog = builder.create();
    trainDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override/*from w  ww. j  a  v  a  2 s.  c om*/
        public void onShow(DialogInterface dialog) {
            Button positive = trainDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    EditText etName = (EditText) trainDialog.findViewById(R.id.edittext_training_name);
                    String trainName = etName.getText().toString();
                    // Validating form fields
                    // Check if program name changed
                    if (!trainName.equals(oldTrain.getName())) {
                        // If chanded - check it
                        // Check if empty
                        if (trainName.isEmpty()) {
                            Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_empty),
                                    Toast.LENGTH_SHORT).show();
                            return;
                        }
                        // Check if training already exists

                        TrainingDAO td = new TrainingDAO(MainActivity.this);
                        long programId = getActiveProgramId();
                        if (td.getTrainingByName(programId, trainName)
                                .getId() != TrainingDAO.ID_TRAINING_NOT_FOUND) {
                            Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_exists),
                                    Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        // if program name stays the same - do nothing
                        trainDialog.dismiss();
                        return;

                    }

                    // if everything is ok - update program record
                    TrainingDAO td = new TrainingDAO(activity);
                    Training t = new Training();
                    long programId = getActiveProgramId();
                    t.setName(trainName);
                    t.setProgramId(programId);
                    t.setId(oldTrain.getId());
                    td.updateTraining(t);
                    Toast.makeText(activity, getText(R.string.toast_upd_training_ok), Toast.LENGTH_SHORT)
                            .show();
                    tla.updateTraining(t);
                    trainDialog.dismiss();
                }
            });

        }
    });
    trainDialog.show();
    // Initiate data with old program entry
    EditText etName = (EditText) trainDialog.findViewById(R.id.edittext_training_name);
    etName.setText(oldTrain.getName());
}

From source file:com.fitme.MainActivity.java

public void onProgramEditRequested(final ProgramRow oldProg, final ProgramListAdapter pda) {
    final Activity activity = MainActivity.this;
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(getString(R.string.title_upd_program_dialog));
    builder.setView(getLayoutInflater().inflate(R.layout.dialog_add_program, null));
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog programDialog = builder.create();
    programDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override/*from ww  w.  j av a2s . co m*/
        public void onShow(DialogInterface dialog) {
            Button positive = programDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    EditText etName = (EditText) programDialog.findViewById(R.id.edittext_program_name);
                    EditText etDesc = (EditText) programDialog.findViewById(R.id.edittext_program_desc);
                    String programName = etName.getText().toString();
                    String programDesc = etDesc.getText().toString();
                    // Validating form fields
                    // Check if program name changed
                    if (!programName.equals(oldProg.getName())) {
                        // If chanded - check it
                        // Check if empty
                        if (programName.isEmpty()) {
                            Toast.makeText(MainActivity.this, getString(R.string.toast_err_program_empty),
                                    Toast.LENGTH_SHORT).show();
                            return;
                        }
                        // Check if program already exists
                        ProgramDAO pd = new ProgramDAO(MainActivity.this);
                        if (pd.getProgramByName(programName).getId() != ProgramDAO.ID_PROGRAM_NOT_FOUND) {
                            Toast.makeText(MainActivity.this, getString(R.string.toast_err_program_exists),
                                    Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        // if program name stays the same - check description
                        // if description is the same - nothing happens
                        if (programDesc.equals(oldProg.getDescription())) {
                            programDialog.dismiss();
                            return;
                        }
                    }

                    // if everything is ok - update program record
                    Program p = new Program();
                    p.setName(programName);
                    p.setDescription(programDesc);
                    ProgramDAO pd = new ProgramDAO(activity);
                    pd.updateByName(oldProg.getName(), p);
                    Toast.makeText(activity, getText(R.string.toast_upd_program_ok), Toast.LENGTH_SHORT).show();
                    pda.updateProgram(oldProg.getName(), p);
                    programDialog.dismiss();
                }
            });

        }
    });
    programDialog.show();
    // Initiate data with old program entry
    EditText etName = (EditText) programDialog.findViewById(R.id.edittext_program_name);
    EditText etDesc = (EditText) programDialog.findViewById(R.id.edittext_program_desc);
    etName.setText(oldProg.getName());
    etDesc.setText(oldProg.getDescription());
}

From source file:com.fitme.MainActivity.java

public void onExerciseCreationRequested(final String trainName, final TrainingsListAdapter tla) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_exercise_dialog);
    View view = getLayoutInflater().inflate(R.layout.dialog_add_exercise, null);
    builder.setView(view);//from w  w w  .  j  av  a  2s  .  co m
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialogEx = builder.create();
    dialogEx.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button positive = dialogEx.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
                    Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
                    NumberPicker numpickRepeats = (NumberPicker) dialogEx
                            .findViewById(R.id.numberpicker_repeats_ex);
                    //Since we decide to have all spinners pre-populated no need to check data
                    Exercise e = new Exercise();
                    e.setName(spinExName.getSelectedItem().toString());
                    e.setMuscleGroup(spinMuscleGroup.getSelectedItem().toString());
                    e.setRepeats(numpickRepeats.getValue());
                    //Identifying program and training
                    long programId = MainActivity.this.getActiveProgramId();
                    TrainingDAO td = new TrainingDAO(MainActivity.this);
                    long trId = td.getTrainingByName(programId, trainName).getId();
                    e.setTrainId(trId);

                    //Insert new entry to db
                    ExerciseDAO ed = new ExerciseDAO(MainActivity.this);
                    long exId = ed.createExercise(e).getId();
                    e.setId(exId);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_exercise_ok),
                            Toast.LENGTH_SHORT).show();
                    tla.addExercise(e, trainName);
                    dialogEx.dismiss();
                }
            });

        }
    });
    dialogEx.show();
    // Populate dialog fields
    NumberPicker np = (NumberPicker) dialogEx.findViewById(R.id.numberpicker_repeats_ex);
    final Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
    final Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
    np.setMaxValue(Exercise.MAX_REPEATS);
    np.setMinValue(Exercise.MIN_REPEATS);

    //Filling muscle groups spinner
    String[] muscleGroups = getResources().getStringArray(R.array.muscle_groups);

    ArrayAdapter<String> mgAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            muscleGroups);
    spinMuscleGroup.setAdapter(mgAdapter);

    spinMuscleGroup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String arrayName = ("exercises_" + spinMuscleGroup.getSelectedItem().toString()).toLowerCase();
            int id = getResources().getIdentifier(arrayName, "array", MainActivity.this.getPackageName());
            String[] exercises = getResources().getStringArray(id);
            ArrayAdapter<String> exAdapter = new ArrayAdapter<String>(MainActivity.this,
                    android.R.layout.simple_spinner_item, exercises);
            spinExName.setAdapter(exAdapter);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    spinMuscleGroup.setSelection(1);

}

From source file:com.fitme.MainActivity.java

/**
 * A fragment representing a exercises managment section of the app
 *//*from  w  w  w.j a v a 2s . c  om*/

private void onAddProgramRequested(final ProgramListAdapter pda) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_program_dialog);
    builder.setView(this.getLayoutInflater().inflate(R.layout.dialog_add_program, null));
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog programDialog = builder.create();
    programDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button positive = programDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Program p = new Program();
                    EditText etName = (EditText) programDialog.findViewById(R.id.edittext_program_name);
                    EditText etDesc = (EditText) programDialog.findViewById(R.id.edittext_program_desc);
                    String programName = etName.getText().toString();
                    String programDesc = etDesc.getText().toString();
                    // Check if form filled correct
                    // Check if program name is empty
                    if (programName.isEmpty()) {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_err_program_empty),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // Check if program already exists
                    ProgramDAO pd = new ProgramDAO(MainActivity.this);
                    if (pd.getProgramByName(programName).getId() != ProgramDAO.ID_PROGRAM_NOT_FOUND) {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_err_program_exists),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // If everything is ok - then add new program
                    p.setName(programName);
                    p.setDescription(programDesc);
                    pd.createProgram(p);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_program_ok),
                            Toast.LENGTH_SHORT).show();
                    pda.addProgram(p);
                    programDialog.dismiss();
                }
            });
        }
    });
    programDialog.show();

}

From source file:no.kreativo.badetemperaturer.MainActivity.java

private void showAboutPopup() {

    final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.about))
            .setMessage(Html.fromHtml(// w ww. j a v  a 2s .  c  om
                    "<a href=\"http://www.yr.no/observasjonar/badetemperaturar.html\n\">Badetemperaturene blir "
                            + "rapportert til yr.no og Reiseradioen av hver enkelt campingplass/badestrand. Mlingene flger ikke vanlig "
                            + "meteorologisk standard, men gir en god indikasjon p vanntemperaturen. Badetemperaturene i Oslo er levert "
                            + "av Oslo kommune, Akershus av badevann.no.</a>"))
            .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
    dialog.show();

    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());

}

From source file:com.fitme.MainActivity.java

public void onTrainingCreationRequested(final TrainingsListAdapter tla) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_training_dialog);
    View addTrainDialogView = getLayoutInflater().inflate(R.layout.dialog_add_training, null);
    builder.setView(addTrainDialogView);

    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);

    final AlertDialog trainingDialog = builder.create();

    trainingDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override/*from  w  ww .  ja v a2 s  . c om*/
        public void onShow(DialogInterface dialog) {
            Button positive = trainingDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // handle OK

                    EditText etName = (EditText) trainingDialog.findViewById(R.id.edittext_training_name);
                    String trainingName = etName.getText().toString();

                    // Check if form filled correct
                    // Check if training name is empty
                    if (trainingName.isEmpty()) {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_empty),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // Check if training already exists
                    long programId = getActiveProgramId();
                    TrainingDAO td = new TrainingDAO(MainActivity.this);
                    if (td.getTrainingByName(programId, trainingName)
                            .getId() != TrainingDAO.ID_TRAINING_NOT_FOUND) {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_exists),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // If everything is ok - then add new program
                    Training t = new Training();
                    t.setName(trainingName);
                    t.setProgramId(programId);
                    //Insert entry to db
                    td.createTraining(t);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_training_ok),
                            Toast.LENGTH_SHORT).show();
                    tla.addTraining(t);
                    trainingDialog.dismiss();
                }
            });

            Button negative = trainingDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
            negative.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    trainingDialog.dismiss();

                }
            });

        }
    });
    trainingDialog.show();
}

From source file:nz.Intelx.DroidNetLogin.DroidNetLoginActivity.java

public void alert(String msg, Activity a) {

    final Activity act = a;
    final AlertDialog builder = new AlertDialog.Builder(a).setMessage(Html.fromHtml(msg)).setCancelable(false)
            .setNegativeButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    if (act != null)
                        act.finish();/*www  . j a v  a2s.c  om*/
                    else
                        dialog.cancel();
                }
            }).show();
    ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:de.syss.MifareClassicTool.Activities.MainMenu.java

/**
 * Show the about dialog./*from  www  .j  av  a2  s .  co  m*/
 */
private void onShowAboutDialog() {
    CharSequence styledText = Html.fromHtml(getString(R.string.dialog_about_mct, Common.getVersionCode()));
    AlertDialog ad = new AlertDialog.Builder(this).setTitle(R.string.dialog_about_mct_title)
            .setMessage(styledText).setIcon(R.mipmap.ic_launcher)
            .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing.
                }
            }).create();
    ad.show();
    // Make links clickable.
    ((TextView) ad.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}