Back to project page checkit.
The source code is released under:
GNU General Public License
If you think the Android project checkit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * Dialog fragment containing EditText. *//w w w . j a v a2s. c om * @author Yujian Zhang <yujian{dot}zhang[at]gmail(dot)com> * * License: * GNU General Public License v2 * http://www.gnu.org/licenses/gpl-2.0.html * Copyright (C) 2011-2012 Yujian Zhang */ package net.whily.android.checkit; import android.os.Bundle; import android.util.*; import android.view.LayoutInflater; import android.view.View; import android.widget.RadioButton; import android.widget.RadioGroup; public final class SelectionDialogFragment extends CustomDialogFragment { private RadioGroup group; private String[] selections; public static SelectionDialogFragment newInstance(int titleId, String[] selections) { SelectionDialogFragment sdf = new SelectionDialogFragment(); sdf.titleId = titleId; sdf.selections = selections; return sdf; } @Override /** * Return string of corresponding id. */ public CharSequence getMessage() { return "" + group.getCheckedRadioButtonId(); } @Override public View onInflateDialog(Bundle icicle) { LayoutInflater li = LayoutInflater.from(getActivity()); View v = li.inflate(R.layout.selection, null); group = (RadioGroup)v.findViewById(R.id.selection_list); RadioGroup.LayoutParams rg = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT); for (int i = 0; i < selections.length; ++i) { RadioButton rb = new RadioButton(getActivity()); rb.setId(i); rb.setText(selections[i]); // Change dp to pixels. float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 266, getResources().getDisplayMetrics()); rb.setWidth((int)px); rb.setTextAppearance(getActivity(), android.R.attr.textAppearanceMedium); group.addView(rb, rg); } if (icicle != null) { group.check(icicle.getInt("selection")); } else { group.check(0); } return v; } @Override public void onSaveInstanceState(Bundle icicle) { icicle.putInt("selection", group.getCheckedRadioButtonId()); super.onPause(); } }