Java tutorial
/* Swisscom Safe Connect Copyright (C) 2014 Swisscom This program 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. This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ package com.swisscom.safeconnect.fragment; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.text.method.LinkMovementMethod; import android.widget.ListAdapter; import android.widget.TextView; import com.swisscom.safeconnect.R; public class PipeDialogFragment extends DialogFragment { private String title = ""; private String msg = null; private DialogInterface.OnClickListener positiveListener = null; private DialogInterface.OnClickListener selectionListener = null; private ListAdapter listAdapter = null; private boolean cancelButton = false; public String getTagName() { return "PipeDialogFragment"; } @Override public void onStart() { super.onStart(); // clickable hyperlinks TextView tvMessage = (TextView) getDialog().findViewById(android.R.id.message); if (tvMessage != null) { tvMessage.setMovementMethod(LinkMovementMethod.getInstance()); } } public void setTitle(String title) { this.title = title; } public void setMessage(String msg) { this.msg = msg; } public void setOnPositiveClickListener(DialogInterface.OnClickListener listener) { positiveListener = listener; } public void setSelectionListener(DialogInterface.OnClickListener listener) { selectionListener = listener; } public void setCancelButton(boolean cancelButton) { this.cancelButton = cancelButton; } public void setListAdapter(ListAdapter listAdapter) { this.listAdapter = listAdapter; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreateDialog(savedInstanceState); CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(getActivity()); builder.setTitle(title); if (msg != null) { builder.setMessage(msg); } if (listAdapter != null) { builder.setSingleChoiceItems(listAdapter, 0, selectionListener); } if (positiveListener != null) { builder.setPositiveButton(R.string.lab_btn_ok, positiveListener); } if (cancelButton) { builder.setNegativeButton(R.string.lab_btn_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }); } return builder.createCustomAlertDialog(); } }