Example usage for android.widget RadioGroup setOnCheckedChangeListener

List of usage examples for android.widget RadioGroup setOnCheckedChangeListener

Introduction

In this page you can find the example usage for android.widget RadioGroup setOnCheckedChangeListener.

Prototype

public void setOnCheckedChangeListener(OnCheckedChangeListener listener) 

Source Link

Document

Register a callback to be invoked when the checked radio button changes in this group.

Usage

From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayPageFragment.java

private void setOnCheckedChangeListener(RadioGroup radioGroup, final SelectOneField radioGroupField) {
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override/*from   ww  w . j a  v a  2 s. c  o  m*/
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            View radioButton = radioGroup.findViewById(i);
            int idx = radioGroup.indexOfChild(radioButton);
            radioGroupField.setAnswer(idx);
        }
    });
}

From source file:com.kubotaku.android.sample.sensordataviewer.fragments.SelectStreamTimeFragment.java

@Override
protected void setupViews() {

    loadSelectTimeSettings();//from w  ww . ja  v  a 2  s .c  om

    final View v = getView();

    RadioGroup rgType = (RadioGroup) v.findViewById(R.id.select_time_rg_type);
    rgType.setOnCheckedChangeListener(onTypeCheckedChangeListener);

    switch (this.selectTimeType) {
    default:
    case AppPreferences.SELECT_TIME_TYPE_PRESET:
        rgType.check(R.id.select_time_rb_preset);
        break;

    case AppPreferences.SELECT_TIME_TYPE_DETAIL:
        rgType.check(R.id.select_time_rb_detail);
        break;
    }

    // ---------------
    // Preset

    RadioGroup rgPreset = (RadioGroup) v.findViewById(R.id.select_time_rg_preset);
    rgPreset.setOnCheckedChangeListener(onPresetCheckedChangeListener);

    switch (this.selectTimePresetIndex) {
    default:
    case AppPreferences.TIME_PRESET_1HOUR:
        rgPreset.check(R.id.select_time_rb_1hour);
        break;

    case AppPreferences.TIME_PRESET_3HOUR:
        rgPreset.check(R.id.select_time_rb_3hour);
        break;

    case AppPreferences.TIME_PRESET_6HOUR:
        rgPreset.check(R.id.select_time_rb_6hour);
        break;

    case AppPreferences.TIME_PRESET_12HOUR:
        rgPreset.check(R.id.select_time_rb_12hour);
        break;

    case AppPreferences.TIME_PRESET_24HOUR:
        rgPreset.check(R.id.select_time_rb_24hour);
        break;
    }

    // ---------------
    // Detail

    Button btnDateFrom = (Button) v.findViewById(R.id.select_time_btn_date_from);
    btnDateFrom.setOnClickListener(onClickDateTimeSelectBtnListener);

    Button btnTimeFrom = (Button) v.findViewById(R.id.select_time_btn_time_from);
    btnTimeFrom.setOnClickListener(onClickDateTimeSelectBtnListener);

    Button btnDateTo = (Button) v.findViewById(R.id.select_time_btn_date_to);
    btnDateTo.setOnClickListener(onClickDateTimeSelectBtnListener);

    Button btnTimeTo = (Button) v.findViewById(R.id.select_time_btn_time_to);
    btnTimeTo.setOnClickListener(onClickDateTimeSelectBtnListener);

    updateDateTimeBtnText();

    // ---------------

    Button btnOk = (Button) v.findViewById(R.id.select_time_btn_ok);
    btnOk.setOnClickListener(onClickOkCancelBtnListener);

    Button btnCancel = (Button) v.findViewById(R.id.select_time_btn_cancel);
    btnCancel.setOnClickListener(onClickOkCancelBtnListener);
}

From source file:com.github.johnpersano.supertoasts.demo.fragments.AttributeRadioGroupFragment.java

@Nullable
@Override/*  www  .j  a  v a  2  s . co  m*/
@SuppressWarnings("ConstantConditions")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_attribute_radiogroup, container, false);

    // Make sure the Fragment has found its arguments
    if (this.getArguments() == null) {
        throw new IllegalArgumentException(
                getClass().getName().concat(" cannot be " + "instantiated without arguments."));
    }

    final TextView subtitleTextView = (TextView) view.findViewById(R.id.subtitle);
    subtitleTextView.setText(getArguments().getString(ARG_SUBTITLE));

    final TextView summaryTextView = (TextView) view.findViewById(R.id.summary);
    summaryTextView.setText(getArguments().getString(ARG_SUMMARY));

    final RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.radiogroup);
    for (String string : getArguments().getStringArrayList(ARG_ARRAY)) {
        final RadioButton radioButton = new RadioButton(getActivity());
        radioButton.setText(string);
        radioButton.setId(ViewUtils.generateViewId());
        radioGroup.addView(radioButton);
    }
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
                    .putInt(getArguments().getString(ARG_TITLE),
                            group.indexOfChild(group.findViewById(group.getCheckedRadioButtonId())))
                    .commit();
        }
    });

    // RadioGroup.check() is misleading, we must check the RadioButton manually
    ((RadioButton) radioGroup.getChildAt(PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getInt(getArguments().getString(ARG_TITLE), 0))).setChecked(true);

    return view;
}

From source file:com.cw.litenote.config.Config.java

void selectStyleDialog(View view) {
    mContext = getActivity();//from   w w w.  j av  a 2 s .c  o  m
    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

    builder.setTitle(R.string.config_set_style_title).setPositiveButton(R.string.btn_OK, listener_ok)
            .setNegativeButton(R.string.btn_Cancel, null);

    // inflate select style layout
    mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = mInflater.inflate(R.layout.select_style, null);
    RadioGroup RG_view = (RadioGroup) view.findViewById(R.id.radioGroup1);

    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio0), 0);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio1), 1);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio2), 2);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio3), 3);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio4), 4);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio5), 5);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio6), 6);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio7), 7);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio8), 8);
    setButtonColor((RadioButton) RG_view.findViewById(R.id.radio9), 9);

    builder.setView(view);

    RadioGroup radioGroup = (RadioGroup) RG_view.findViewById(R.id.radioGroup1);
    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup RG, int id) {
            mStyle = RG.indexOfChild(RG.findViewById(id));
        }
    });

    dialog = builder.create();
    dialog.show();
}

From source file:com.android.fastexample.adapter.FragmentTabAdapter.java

public FragmentTabAdapter(FragmentActivity fragmentActivity, List<Fragment> fragments, int fragmentContentId,
        RadioGroup rgs) {
    this.fragments = fragments;
    this.rgs = rgs;
    this.fragmentActivity = fragmentActivity;
    this.fragmentContentId = fragmentContentId;

    // /*  w  w w. ja  v a2 s.c  o m*/
    FragmentTransaction ft = fragmentActivity.getSupportFragmentManager().beginTransaction();
    ft.add(fragmentContentId, fragments.get(0));
    ft.commit();
    rgs.setOnCheckedChangeListener(this);
}

From source file:com.hp.mss.printsdksample.fragment.TabFragmentPrintLayout.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View inflatedView = inflater.inflate(R.layout.tab_fragment_print_layout, container, false);
    filePickerLayout = (RelativeLayout) inflatedView.findViewById(R.id.filePickerLayout);

    RadioGroup layoutRadioGroup = (RadioGroup) inflatedView.findViewById(R.id.layoutRadioGroup);
    layoutRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(layoutRadioGroup, layoutRadioGroup.getCheckedRadioButtonId());

    RadioGroup layoutMarginRadioGroup = (RadioGroup) inflatedView.findViewById(R.id.layoutMarginRadioGroup);
    layoutMarginRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(layoutMarginRadioGroup, layoutMarginRadioGroup.getCheckedRadioButtonId());

    SwitchCompat metricsSwitch = (SwitchCompat) inflatedView.findViewById(R.id.metricsRadioGroup);
    metricsSwitch.setOnCheckedChangeListener(this);
    onCheckedChanged(metricsSwitch, metricsSwitch.isChecked());

    RadioGroup contentRadioGroup = (RadioGroup) inflatedView.findViewById(R.id.contentRadioGroup);
    contentRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(contentRadioGroup, contentRadioGroup.getCheckedRadioButtonId());

    RadioGroup deviceIdRadioGroup = (RadioGroup) inflatedView.findViewById(R.id.deviceIdRadioGroup);
    deviceIdRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(deviceIdRadioGroup, deviceIdRadioGroup.getCheckedRadioButtonId());

    tagText = (EditText) inflatedView.findViewById(R.id.tagEditText);
    valueText = (EditText) inflatedView.findViewById(R.id.valueEditText);
    LinearLayout customData = (LinearLayout) inflatedView.findViewById(R.id.customData);
    showCustomData = customData.getVisibility() == View.VISIBLE;

    FloatingActionButton printButton = (FloatingActionButton) inflatedView.findViewById(R.id.printBtn);
    printButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            continueButtonClicked(v);/*from   w w w  .  j  ava 2  s .  c  om*/
        }
    });

    Button buttonPick = (Button) inflatedView.findViewById(R.id.buttonPick);
    buttonPick.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType(getContentMimeType());
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICKFILE_RESULT_CODE);
        }
    });

    mediaSize5x7 = new PrintAttributes.MediaSize("na_5x7_5x7in", "5 x 7", 5000, 7000);

    return inflatedView;
}

From source file:org.deviceconnect.android.deviceplugin.host.activity.KeyEventProfileActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.keyevent_main);

    // Get Application class instance.
    mApp = (HostDeviceApplication) this.getApplication();

    // Set button touchlistener. (Ten Key Emulated)
    findViewById(R.id.button_0).setOnTouchListener(this);
    findViewById(R.id.button_1).setOnTouchListener(this);
    findViewById(R.id.button_2).setOnTouchListener(this);
    findViewById(R.id.button_3).setOnTouchListener(this);
    findViewById(R.id.button_4).setOnTouchListener(this);
    findViewById(R.id.button_5).setOnTouchListener(this);
    findViewById(R.id.button_6).setOnTouchListener(this);
    findViewById(R.id.button_7).setOnTouchListener(this);
    findViewById(R.id.button_8).setOnTouchListener(this);
    findViewById(R.id.button_9).setOnTouchListener(this);
    findViewById(R.id.button_dot).setOnTouchListener(this);
    findViewById(R.id.button_enter).setOnTouchListener(this);
    findViewById(R.id.button_keyevent_close).setOnTouchListener(this);

    RadioGroup radioGroup = (RadioGroup) findViewById(R.id.RadioGroup);
    // Set default select radio button.
    radioGroup.check(R.id.radioButton1);
    mKeyMode = KeyMode.STD_KEY;/*from   w  ww  .  jav  a 2 s.  c  o  m*/
    // set radiogroup changelistener
    radioGroup.setOnCheckedChangeListener(this);

    // Get serviceId.
    Intent intent = getIntent();
    mServiceId = intent.getStringExtra(DConnectMessage.EXTRA_SERVICE_ID);
}

From source file:com.smc.jobs4smcyouth.Fragments.Print.PrintLayoutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View inflatedView = inflater.inflate(com.smc.jobs4smcyouth.R.layout.fragment_print_layout, container,
            false);//  w  w w.  ja va 2  s  . c  om
    filePickerLayout = (RelativeLayout) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.filePickerLayout);

    RadioGroup layoutRadioGroup = (RadioGroup) inflatedView
            .findViewById(com.smc.jobs4smcyouth.R.id.layoutRadioGroup);
    layoutRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(layoutRadioGroup, layoutRadioGroup.getCheckedRadioButtonId());

    RadioGroup layoutMarginRadioGroup = (RadioGroup) inflatedView
            .findViewById(com.smc.jobs4smcyouth.R.id.layoutMarginRadioGroup);
    layoutMarginRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(layoutMarginRadioGroup, layoutMarginRadioGroup.getCheckedRadioButtonId());

    SwitchCompat metricsSwitch = (SwitchCompat) inflatedView
            .findViewById(com.smc.jobs4smcyouth.R.id.metricsRadioGroup);
    metricsSwitch.setOnCheckedChangeListener(this);
    onCheckedChanged(metricsSwitch, metricsSwitch.isChecked());

    RadioGroup contentRadioGroup = (RadioGroup) inflatedView
            .findViewById(com.smc.jobs4smcyouth.R.id.contentRadioGroup);
    contentRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(contentRadioGroup, contentRadioGroup.getCheckedRadioButtonId());

    RadioGroup deviceIdRadioGroup = (RadioGroup) inflatedView
            .findViewById(com.smc.jobs4smcyouth.R.id.deviceIdRadioGroup);
    deviceIdRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(deviceIdRadioGroup, deviceIdRadioGroup.getCheckedRadioButtonId());

    tagText = (EditText) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.tagEditText);
    valueText = (EditText) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.valueEditText);
    LinearLayout customData = (LinearLayout) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.customData);
    showCustomData = customData.getVisibility() == View.VISIBLE;

    FloatingActionButton printButton = (FloatingActionButton) inflatedView
            .findViewById(com.smc.jobs4smcyouth.R.id.printBtn);
    printButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            continueButtonClicked(v);
        }
    });

    Button buttonPick = (Button) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.buttonPick);
    buttonPick.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType(getContentMimeType());
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICKFILE_RESULT_CODE);
        }
    });

    mediaSize5x7 = new PrintAttributes.MediaSize("na_5x7_5x7in", "5 x 7", 5000, 7000);

    return inflatedView;
}

From source file:jmri.enginedriver.intro_buttons.java

@SuppressWarnings("ConstantConditions")
@Override/*from  w w  w  . j av a2s  .  c  o  m*/
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    Log.d("Engine_Driver", "intro_buttons");
    super.onActivityCreated(savedInstanceState);
    prefs = this.getActivity().getSharedPreferences("jmri.enginedriver_preferences", 0);
    prefDisplaySpeedButtons = prefs.getBoolean("display_speed_arrows_buttons", false);
    prefHideSlider = prefs.getBoolean("hide_slider_preference", false);

    v = (RadioButton) getView().findViewById(R.id.intro_buttons_slider_name);
    v.setText(this.getActivity().getApplicationContext().getResources().getString(R.string.introButtonsSlider));
    v = (RadioButton) getView().findViewById(R.id.intro_buttons_slider_and_buttons_name);
    v.setText(this.getActivity().getApplicationContext().getResources()
            .getString(R.string.introButtonsSliderAndButtons));
    v = (RadioButton) getView().findViewById(R.id.intro_buttons_no_slider_name);
    v.setText(
            this.getActivity().getApplicationContext().getResources().getString(R.string.introButtonsNoSlider));

    RadioGroup radioGroup = getView().findViewById(R.id.intro_buttons_radio_group);

    radioGroup.clearCheck();
    if (!prefDisplaySpeedButtons && !prefHideSlider) {
        radioGroup.check(R.id.intro_buttons_slider_name);
    } else if (prefDisplaySpeedButtons && !prefHideSlider) {
        radioGroup.check(R.id.intro_buttons_slider_and_buttons_name);
    } else {
        radioGroup.check(R.id.intro_buttons_no_slider_name);
    }
    radioGroup.jumpDrawablesToCurrentState();

    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @SuppressLint("ApplySharedPref")
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.intro_buttons_slider_name) {
                displaySpeedButtons = false;
                hideSlider = false;
            } else if (checkedId == R.id.intro_buttons_slider_and_buttons_name) {
                displaySpeedButtons = true;
                hideSlider = false;
            } else if (checkedId == R.id.intro_buttons_no_slider_name) {
                displaySpeedButtons = true;
                hideSlider = true;
            }
            prefs.edit().putBoolean("display_speed_arrows_buttons", displaySpeedButtons).commit();
            prefs.edit().putBoolean("hide_slider_preference", hideSlider).commit();
        }
    });

}

From source file:com.google.android.car.kitchensink.hvac.HvacTestFragment.java

private void configureFanPosition(View v, CarPropertyConfig prop) {
    mZoneForFanPosition = prop.getFirstAndOnlyAreaId();
    RadioGroup rg = (RadioGroup) v.findViewById(R.id.rgFanPosition);
    rg.setOnCheckedChangeListener((group, checkedId) -> {
        int position;
        switch (checkedId) {
        case R.id.rbPositionFace:
            position = CarHvacManager.FAN_POSITION_FACE;
            break;
        case R.id.rbPositionFloor:
            position = CarHvacManager.FAN_POSITION_FLOOR;
            break;
        case R.id.rbPositionFaceAndFloor:
            position = CarHvacManager.FAN_POSITION_FACE_AND_FLOOR;
            break;
        case R.id.rbPositionDefrost:
            position = CarHvacManager.FAN_POSITION_DEFROST;
            break;
        case R.id.rbPositionDefrostAndFloor:
            position = CarHvacManager.FAN_POSITION_DEFROST_AND_FLOOR;
            break;
        default:/*w w  w . j a  v  a 2  s . com*/
            throw new IllegalStateException("Unexpected fan position: " + checkedId);
        }
        try {
            mCarHvacManager.setIntProperty(CarHvacManager.ID_ZONED_FAN_POSITION, mZoneForFanPosition, position);
        } catch (CarNotConnectedException e) {
            Log.e(TAG, "Failed to set HVAC integer property", e);
        }
    });

    mRbFanPositionFace = (RadioButton) v.findViewById(R.id.rbPositionFace);
    mRbFanPositionFace.setClickable(true);
    mRbFanPositionFloor = (RadioButton) v.findViewById(R.id.rbPositionFloor);
    mRbFanPositionFloor.setClickable(true);
    mRbFanPositionFaceAndFloor = (RadioButton) v.findViewById(R.id.rbPositionFaceAndFloor);
    mRbFanPositionFaceAndFloor.setClickable(true);
    mRbFanPositionDefrost = (RadioButton) v.findViewById(R.id.rbPositionDefrost);
    mRbFanPositionDefrost.setClickable(true);
    mRbFanPositionDefrostAndFloor = (RadioButton) v.findViewById(R.id.rbPositionDefrostAndFloor);
    mRbFanPositionDefrostAndFloor.setClickable(true);
}