Java tutorial
package pl.reticular.br.dialogs; /* * Copyright (C) 2016 Piotr Jankowski * * This file is part of Borromean Rings. * * Borromean Rings is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Borromean Rings is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Borromean Rings. If not, see <http://www.gnu.org/licenses/>. */ import android.app.Dialog; import android.content.DialogInterface; import android.content.res.Resources; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import pl.reticular.br.R; import pl.reticular.br.utils.PrefsHelper; public class SegmentNumberDialog extends DialogFragment { @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.segment_number) .setItems(R.array.segment_numbers, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Resources res = getContext().getResources(); String str = res.getStringArray(R.array.segment_numbers)[which]; int val = Integer.parseInt(str); PrefsHelper.getInstance().setSegmentNumber(val); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); return builder.create(); } }