Android Open Source - checkit Selection Dialog Fragment






From Project

Back to project page checkit.

License

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.

Java Source Code

/**
 * 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();
  }
}




Java Source Code List

net.whily.android.checkit.AboutActivity.java
net.whily.android.checkit.Alert.java
net.whily.android.checkit.CheckActivity.java
net.whily.android.checkit.CheckedItem.java
net.whily.android.checkit.ChecklistMetadata.java
net.whily.android.checkit.ChecklistProvider.java
net.whily.android.checkit.CustomDialogFragment.java
net.whily.android.checkit.ExternalStorage.java
net.whily.android.checkit.HomeActivity.java
net.whily.android.checkit.OnDialogDoneListener.java
net.whily.android.checkit.PromptDialogFragment.java
net.whily.android.checkit.SelectionDialogFragment.java
net.whily.android.checkit.SettingsActivity.java
net.whily.android.checkit.Util.java