Example usage for android.app AlertDialog getButton

List of usage examples for android.app AlertDialog getButton

Introduction

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

Prototype

public Button getButton(int whichButton) 

Source Link

Document

Gets one of the buttons used in the dialog.

Usage

From source file:de.baumann.hhsmoodle.data_count.Count_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    lv = (ListView) rootView.findViewById(R.id.listNotes);
    filter = (EditText) rootView.findViewById(R.id.myFilter);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);

    ImageButton ib_hideKeyboard = (ImageButton) rootView.findViewById(R.id.ib_hideKeyboard);
    ib_hideKeyboard.setOnClickListener(new View.OnClickListener() {
        @Override//w w  w.  j  a va  2s.c  o  m
        public void onClick(View view) {
            if (filter.getText().length() > 0) {
                filter.setText("");
            } else {
                setTitle();
                helper_main.hideFilter(getActivity(), filter_layout, imgHeader);
                setCountList();
            }
        }
    });

    fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1);
    fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2);
    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1);
    FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!isFABOpen) {
                showFABMenu();
            } else {
                closeFABMenu();
            }
        }
    });

    fab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();
            final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
            View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);
            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
            edit_title.setHint(R.string.bookmark_edit_title);
            builder.setTitle(R.string.count_title);
            builder.setView(dialogView);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final android.app.AlertDialog dialog2 = builder.create();
            dialog2.show();

            dialog2.getButton(android.app.AlertDialog.BUTTON_POSITIVE)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //Do stuff, possibly set wantToCloseDialog to true then...

                            String inputTitle = edit_title.getText().toString().trim();

                            Count_DbAdapter db = new Count_DbAdapter(getActivity());
                            db.open();

                            if (db.isExist(inputTitle)) {
                                Snackbar.make(edit_title, getActivity().getString(R.string.toast_newTitle),
                                        Snackbar.LENGTH_LONG).show();
                            } else {
                                dialog2.dismiss();
                                db.insert(inputTitle, sharedPref.getString("count_content", ""), "3", "",
                                        helper_main.createDate());
                                sharedPref.edit().putString("count_content", "").apply();
                                setCountList();
                            }
                        }
                    });

            helper_main.showKeyboard(getActivity(), edit_title);
        }
    });

    fab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();
            Intent mainIntent = new Intent(getActivity(), Popup_courseList.class);
            mainIntent.setAction("courseList_count");
            startActivity(mainIntent);
        }
    });

    //calling Notes_DbAdapter
    db = new Count_DbAdapter(getActivity());
    db.open();

    setCountList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:com.docd.purefm.ui.dialogs.FilePropertiesDialog.java

private void initView(@NonNull final View view) {
    final ViewPager pager = (ViewPager) view.findViewById(R.id.tabsContainer);
    pager.setAdapter(mAdapter);/*from  ww  w.j  a v a 2s  .c om*/

    final CompoundButton tab1 = (CompoundButton) view.findViewById(R.id.tab1);
    final CompoundButton tab2 = (CompoundButton) view.findViewById(R.id.tab2);

    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            tab1.setChecked(position == 0);
            tab2.setChecked(position == 1);
            final AlertDialog dialog = (AlertDialog) getDialog();
            if (dialog == null) {
                throw new RuntimeException("The dialog is null");
            }
            final Button positive = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (positive == null) {
                throw new RuntimeException("Can't get positive button");
            }
            positive.setVisibility(
                    position == 0 || !((FilePermissionsPagerItem) mAdapter.getItem(1)).areBoxesEnabled()
                            ? View.GONE
                            : View.VISIBLE);
        }
    });

    tab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tab1.setChecked(true);
            tab2.setChecked(false);
            pager.setCurrentItem(0);
        }
    });

    tab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            tab2.setChecked(true);
            tab1.setChecked(false);
            pager.setCurrentItem(1);
        }
    });
}

From source file:com.hctrom.romcontrol.MainViewActivity.java

private void showThemeChooserDialog() {
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    Adapter adapter = new ArrayAdapter<>(this, R.layout.simple_list_item_single_choice,
            getResources().getStringArray(R.array.theme_items));
    b.setIcon(R.drawable.ic_htc_personalize).setTitle(getString(R.string.theme_chooser_dialog_title))
            .setSingleChoiceItems((ListAdapter) adapter,
                    PreferenceManager.getDefaultSharedPreferences(this).getInt("theme_prefs", 0),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //Invokes method initTheme(int) - next method based on chosen theme
                            initTheme(which);
                        }/*from www .  ja v  a  2s  .c o m*/
                    });
    AlertDialog d = b.create();
    d.show();
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = this.getTheme();
    theme.resolveAttribute(R.attr.colorAccent, typedValue, true);

    Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE);
    cancel.setTextColor(typedValue.data);
    Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE);
    ok.setTextColor(typedValue.data);
    d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
    ListView lv = d.getListView();
    int paddingTop = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_top_padding));
    int paddingBottom = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_bottom_padding));
    lv.setPadding(0, paddingTop, 0, paddingBottom);
}

From source file:com.hctrom.romcontrol.MainViewActivity.java

private void getAvisoBackupDialog() {
    View checkBoxView = View.inflate(this, R.layout.aviso_backup_text, null);
    final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBoxAvisoBackup);
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override/*from www.j  a v a 2s  .  c  om*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (checkBox.isChecked()) {
                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
                        .putInt("aviso_backup", 1).commit();
            } else {
                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
                        .putInt("aviso_backup", 0).commit();
            }
        }
    });
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setView(checkBoxView).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    AlertDialog d = b.create();
    d.show();
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = this.getTheme();
    theme.resolveAttribute(R.attr.colorAccent, typedValue, true);

    Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE);
    cancel.setTextColor(typedValue.data);
    Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE);
    ok.setTextColor(typedValue.data);
    d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
}

From source file:com.fitme.MainActivity.java

/**
 * A fragment representing a exercises managment section of the app
 *//*  ww w  .  j  a  v a  2  s  .co  m*/

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: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 w w.ja va  2  s . com*/
        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:de.baumann.hhsmoodle.fragmentsMain.FragmentBrowser.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {

    case R.id.action_help:
        helper_main.switchToActivity(getActivity(), FragmentBrowser_Help.class, false);
        return true;

    case R.id.action_bookmark:
        helper_main.switchToActivity(getActivity(), Popup_bookmarks.class, false);
        return true;

    case R.id.action_saveBookmark:

        final Bookmarks_DbAdapter db = new Bookmarks_DbAdapter(getActivity());
        db.open();//  www .  j a  v a2  s .  c o  m

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);

        final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
        edit_title.setHint(R.string.bookmark_edit_title);
        edit_title.setText(mWebView.getTitle());

        builder.setView(dialogView);
        builder.setTitle(R.string.bookmark_edit_title);
        builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {

            }
        });
        builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });

        final AlertDialog dialog2 = builder.create();
        // Display the custom alert dialog on interface
        dialog2.show();
        helper_main.showKeyboard(getActivity(), edit_title);

        dialog2.getButton(android.app.AlertDialog.BUTTON_POSITIVE)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //Do stuff, possibly set wantToCloseDialog to true then...
                        String inputTag = edit_title.getText().toString().trim();

                        if (db.isExist(mWebView.getUrl())) {
                            Snackbar.make(edit_title, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG)
                                    .show();
                        } else {
                            db.insert(inputTag, mWebView.getUrl(), "04", "", createDate());
                            dialog2.dismiss();
                            Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show();
                        }
                    }
                });

        return true;

    case R.id.menu_share_screenshot:
        screenshot();

        if (shareFile.exists()) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("image/png");
            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
            sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
            Uri bmpUri = Uri.fromFile(shareFile);
            sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
            startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot))));
        }
        return true;

    case R.id.menu_save_screenshot:
        screenshot();
        return true;

    case R.id.menu_share_link:
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle());
        sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
        startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link))));
        return true;

    case R.id.menu_share_link_browser:
        String url = mWebView.getUrl();
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        getActivity().startActivity(intent);
        return true;

    case R.id.menu_share_link_copy:
        String url2 = mWebView.getUrl();
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("text", url2));
        Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_LONG).show();
        return true;
    }
    return false;
}

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//w w w . j  ava  2s. 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 ww.  j ava 2s .  c o  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);

}