Example usage for android.widget RadioGroup check

List of usage examples for android.widget RadioGroup check

Introduction

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

Prototype

public void check(@IdRes int id) 

Source Link

Document

Sets the selection to the radio button whose identifier is passed in parameter.

Usage

From source file:Main.java

public static void checkRadioGroup(RadioGroup radioGroup, String selectedRadioText) {
    for (int i = 0; i < radioGroup.getChildCount(); i++) {
        RadioButton radio = (RadioButton) radioGroup.getChildAt(i);
        if (radio.getText().equals(selectedRadioText)) {
            radioGroup.check(radio.getId());
            break;
        }//w  w w .  j a va 2  s.co  m
    }
}

From source file:com.cw.litenote.folder.FolderUi.java

public static void addNewFolder(final AppCompatActivity act, final int newTableId,
        final SimpleDragSortCursorAdapter folderAdapter) {
    // get folder name
    final String hintFolderName = act.getResources().getString(R.string.default_folder_name)
            .concat(String.valueOf(newTableId));

    // get layout inflater
    View rootView = act.getLayoutInflater().inflate(R.layout.add_new_folder, null);
    final TouchableEditText editFolderName = (TouchableEditText) rootView.findViewById(R.id.new_folder_name);

    // set cursor
    try {/*  ww  w.j  av a2  s  .co m*/
        Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
        f.setAccessible(true);
        f.set(editFolderName, R.drawable.cursor);
    } catch (Exception ignored) {
    }

    // set hint
    editFolderName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                ((EditText) v).setHint(hintFolderName);
            }
        }
    });

    editFolderName.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ((EditText) v).setText(hintFolderName);
            ((EditText) v).setSelection(hintFolderName.length());
            v.performClick();
            return false;
        }
    });

    // radio buttons
    final RadioGroup mRadioGroup = (RadioGroup) rootView.findViewById(R.id.radioGroup_new_folder_at);

    // get new folder location option
    mPref_add_new_folder_location = act.getSharedPreferences("add_new_folder_option", 0);
    if (mPref_add_new_folder_location.getString("KEY_ADD_NEW_FOLDER_TO", "bottom").equalsIgnoreCase("top")) {
        mRadioGroup.check(mRadioGroup.getChildAt(0).getId());
        mAddFolderAt = 0;
    } else if (mPref_add_new_folder_location.getString("KEY_ADD_NEW_FOLDER_TO", "bottom")
            .equalsIgnoreCase("bottom")) {
        mRadioGroup.check(mRadioGroup.getChildAt(1).getId());
        mAddFolderAt = 1;
    }

    // update new folder location option
    mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup RG, int id) {
            mAddFolderAt = mRadioGroup.indexOfChild(mRadioGroup.findViewById(id));
            if (mAddFolderAt == 0) {
                mPref_add_new_folder_location.edit().putString("KEY_ADD_NEW_FOLDER_TO", "top").apply();
            } else if (mAddFolderAt == 1) {
                mPref_add_new_folder_location.edit().putString("KEY_ADD_NEW_FOLDER_TO", "bottom").apply();
            }
        }
    });

    // set view to dialog
    Builder builder1 = new Builder(act);
    builder1.setView(rootView);
    final AlertDialog dialog1 = builder1.create();
    dialog1.show();

    // cancel button
    Button btnCancel = (Button) rootView.findViewById(R.id.new_folder_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog1.dismiss();
        }
    });

    // add button
    Button btnAdd = (Button) rootView.findViewById(R.id.new_folder_add);
    btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DB_drawer db_drawer = new DB_drawer(act);

            String folderTitle;
            if (!Util.isEmptyString(editFolderName.getText().toString()))
                folderTitle = editFolderName.getText().toString();
            else
                folderTitle = act.getResources().getString(R.string.default_folder_name)
                        .concat(String.valueOf(newTableId));

            MainAct.mFolderTitles.add(folderTitle);
            // insert new drawer Id and Title
            db_drawer.insertFolder(newTableId, folderTitle, true);

            // insert folder table
            db_drawer.insertFolderTable(newTableId, true);

            // insert initial page table after Add new folder
            if (Define.INITIAL_PAGES_COUNT > 0) {
                for (int i = 1; i <= Define.INITIAL_PAGES_COUNT; i++) {
                    DB_folder dB_folder = new DB_folder(act, newTableId);
                    int style = Util.getNewPageStyle(act);
                    dB_folder.insertPage(DB_folder.getFocusFolder_tableName(), Define.getTabTitle(act, 1), i,
                            style, true);

                    dB_folder.insertPageTable(dB_folder, newTableId, i, true);
                }
            }

            // add new folder to the top
            if (mAddFolderAt == 0) {
                int startCursor = db_drawer.getFoldersCount(true) - 1;
                int endCursor = 0;

                //reorder data base storage for ADD_NEW_TO_TOP option
                int loop = Math.abs(startCursor - endCursor);
                for (int i = 0; i < loop; i++) {
                    swapFolderRows(startCursor, endCursor);
                    if ((startCursor - endCursor) > 0)
                        endCursor++;
                    else
                        endCursor--;
                }

                // update focus folder position
                if (db_drawer.getFoldersCount(true) == 1)
                    setFocus_folderPos(0);
                else
                    setFocus_folderPos(getFocus_folderPos() + 1);

                // update focus folder table Id for Add to top
                Pref.setPref_focusView_folder_tableId(act,
                        db_drawer.getFolderTableId(getFocus_folderPos(), true));

                // update playing highlight if needed
                if (BackgroundAudioService.mMediaPlayer != null)
                    MainAct.mPlaying_folderPos++;
            }

            // recover focus folder table Id
            DB_folder.setFocusFolder_tableId(Pref.getPref_focusView_folder_tableId(act));

            folderAdapter.notifyDataSetChanged();

            //end
            dialog1.dismiss();
            updateFocus_folderPosition();

            MainAct.mAct.invalidateOptionsMenu();
        }
    });
}

From source file:com.kyakujin.android.autoeco.ui.SleepSettingFragment.java

private void setDefaultRadioButton(RadioGroup radioGroup) {
    switch (mSleepTime) {
    case TIME1://from w  w w  .j av  a2s. c o  m
        radioGroup.check(R.id.radioTime1);
        break;
    case TIME2:
        radioGroup.check(R.id.radioTime2);
        break;
    case TIME3:
        radioGroup.check(R.id.radioTime3);
        break;
    case TIME4:
        radioGroup.check(R.id.radioTime4);
        break;
    case TIME5:
        radioGroup.check(R.id.radioTime5);
        break;
    case TIME6:
        radioGroup.check(R.id.radioTime6);
        break;
    default:
    }
}

From source file:com.kyakujin.android.autoeco.ui.BluetoothSettingFragment.java

private void setDefaultRadioButton(RadioGroup radioGroup) {
    int enabled = (mEnabled == true ? 1 : 0);
    switch (enabled) {
    case 1:/*w w w  .  j a v a2s  .  c om*/
        radioGroup.check(R.id.radioBluetoothOn);
        break;
    case 0:
        radioGroup.check(R.id.radioBluetoothOff);
        break;
    default:
    }
}

From source file:com.kyakujin.android.autoeco.ui.SyncSettingFragment.java

private void setDefaultRadioButton(RadioGroup radioGroup) {
    int enabled = (mEnabled == true ? 1 : 0);
    switch (enabled) {
    case 1:/*from   ww  w.j  av a  2s  .  co  m*/
        radioGroup.check(R.id.radioSyncOn);
        break;
    case 0:
        radioGroup.check(R.id.radioSyncOff);
        break;
    default:
    }
}

From source file:com.kyakujin.android.autoeco.ui.WifiSettingFragment.java

private void setDefaultRadioButton(RadioGroup radioGroup) {
    int enabled = (mEnabled == true ? 1 : 0);
    switch (enabled) {
    case 1:/*  w  ww. j  a va2  s .com*/
        radioGroup.check(R.id.radioWifiOn);
        break;
    case 0:
        radioGroup.check(R.id.radioWifiOff);
        break;
    default:
    }
}

From source file:com.kyakujin.android.autoeco.ui.RotateSettingFragment.java

private void setDefaultRadioButton(RadioGroup radioGroup) {
    int enabled = (mEnabled == true ? 1 : 0);
    switch (enabled) {
    case 1://  w  w w  .  ja va  2 s.  com
        radioGroup.check(R.id.radioRotateOn);
        break;
    case 0:
        radioGroup.check(R.id.radioRotateOff);
        break;
    default:
    }
}

From source file:jmri.enginedriver.intro_buttons.java

@SuppressWarnings("ConstantConditions")
@Override/*  w w w.j a  v a  2 s.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:jmri.enginedriver.intro_theme.java

@SuppressWarnings("ConstantConditions")
@Override/*w w  w .  j a v  a 2 s  . c o  m*/
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    Log.d("Engine_Driver", "intro_theme");

    super.onActivityCreated(savedInstanceState);
    prefs = this.getActivity().getSharedPreferences("jmri.enginedriver_preferences", 0);
    currentValue = prefs.getString("prefTheme", this.getActivity().getApplicationContext().getResources()
            .getString(R.string.prefThemeDefaultValue));

    nameEntries = this.getActivity().getApplicationContext().getResources()
            .getStringArray(R.array.prefThemeEntries);
    nameEntryValues = this.getActivity().getApplicationContext().getResources()
            .getStringArray(R.array.prefThemeEntryValues);
    v = (RadioButton) getView().findViewById(R.id.intro_theme_default_name);
    v.setText(nameEntries[0]);
    v = (RadioButton) getView().findViewById(R.id.intro_theme_black_name);
    v.setText(nameEntries[1]);
    v = (RadioButton) getView().findViewById(R.id.intro_theme_outline_name);
    v.setText(nameEntries[2]);
    v = (RadioButton) getView().findViewById(R.id.intro_theme_ultra_name);
    v.setText(nameEntries[3]);
    v = (RadioButton) getView().findViewById(R.id.intro_theme_colorful_name);
    v.setText(nameEntries[4]);

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

    radioGroup.clearCheck();
    if (nameEntryValues[0].equals(currentValue)) {
        radioGroup.check(R.id.intro_theme_default_name);
    } else if (nameEntryValues[1].equals(currentValue)) {
        radioGroup.check(R.id.intro_theme_black_name);
    } else if (nameEntryValues[2].equals(currentValue)) {
        radioGroup.check(R.id.intro_theme_outline_name);
    } else if (nameEntryValues[3].equals(currentValue)) {
        radioGroup.check(R.id.intro_theme_ultra_name);
    } else if (nameEntryValues[4].equals(currentValue)) {
        radioGroup.check(R.id.intro_theme_colorful_name);
    }
    radioGroup.jumpDrawablesToCurrentState();

    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @SuppressLint("ApplySharedPref")
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            int Choice = 0;
            if (checkedId == R.id.intro_theme_default_name) {
                Choice = 0;
            } else if (checkedId == R.id.intro_theme_black_name) {
                Choice = 1;
            } else if (checkedId == R.id.intro_theme_outline_name) {
                Choice = 2;
            } else if (checkedId == R.id.intro_theme_ultra_name) {
                Choice = 3;
            } else if (checkedId == R.id.intro_theme_colorful_name) {
                Choice = 4;
            }
            prefs.edit().putString("prefTheme", nameEntryValues[Choice]).commit();
        }
    });

}

From source file:jmri.enginedriver.intro_throttle_type.java

@SuppressWarnings("ConstantConditions")
@Override//from  ww  w.  jav a 2 s  .c  o  m
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    Log.d("Engine_Driver", "intro_throttle_type");
    super.onActivityCreated(savedInstanceState);
    prefs = this.getActivity().getSharedPreferences("jmri.enginedriver_preferences", 0);
    currentValue = prefs.getString("prefThrottleScreenType", this.getActivity().getApplicationContext()
            .getResources().getString(R.string.prefThrottleScreenTypeDefault));

    nameEntries = this.getActivity().getApplicationContext().getResources()
            .getStringArray(R.array.prefThrottleScreenTypeEntries);
    nameEntryValues = this.getActivity().getApplicationContext().getResources()
            .getStringArray(R.array.prefThrottleScreenTypeEntryValues);
    v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_default_name);
    v.setText(nameEntries[0]);
    v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_simple_name);
    v.setText(nameEntries[1]);
    v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_vertical_name);
    v.setText(nameEntries[2]);
    v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_big_left_name);
    v.setText(nameEntries[3]);
    v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_big_right_name);
    v.setText(nameEntries[4]);
    v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_vertical_left_name);
    v.setText(nameEntries[5]);
    v = (RadioButton) getView().findViewById(R.id.intro_throttle_type_vertical_right_name);
    v.setText(nameEntries[6]);

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

    radioGroup.clearCheck();
    if (nameEntryValues[0].equals(currentValue)) {
        radioGroup.check(R.id.intro_throttle_type_default_name);
    } else if (nameEntryValues[1].equals(currentValue)) {
        radioGroup.check(R.id.intro_throttle_type_simple_name);
    } else if (nameEntryValues[2].equals(currentValue)) {
        radioGroup.check(R.id.intro_throttle_type_vertical_name);
    } else if (nameEntryValues[3].equals(currentValue)) {
        radioGroup.check(R.id.intro_throttle_type_big_left_name);
    } else if (nameEntryValues[4].equals(currentValue)) {
        radioGroup.check(R.id.intro_throttle_type_big_right_name);
    } else if (nameEntryValues[5].equals(currentValue)) {
        radioGroup.check(R.id.intro_throttle_type_vertical_left_name);
    } else if (nameEntryValues[6].equals(currentValue)) {
        radioGroup.check(R.id.intro_throttle_type_vertical_right_name);
    }
    radioGroup.jumpDrawablesToCurrentState();

    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @SuppressLint("ApplySharedPref")
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            int Choice = 0;
            if (checkedId == R.id.intro_throttle_type_default_name) {
                Choice = 0;
            } else if (checkedId == R.id.intro_throttle_type_simple_name) {
                Choice = 1;
            } else if (checkedId == R.id.intro_throttle_type_vertical_name) {
                Choice = 2;
            } else if (checkedId == R.id.intro_throttle_type_big_left_name) {
                Choice = 3;
            } else if (checkedId == R.id.intro_throttle_type_big_right_name) {
                Choice = 4;
            } else if (checkedId == R.id.intro_throttle_type_vertical_left_name) {
                Choice = 5;
            } else if (checkedId == R.id.intro_throttle_type_vertical_right_name) {
                Choice = 6;
            }
            prefs.edit().putString("prefThrottleScreenType", nameEntryValues[Choice]).commit();
        }
    });

}