List of usage examples for android.widget RadioGroup getCheckedRadioButtonId
@IdRes public int getCheckedRadioButtonId()
Returns the identifier of the selected radio button in this group.
From source file:Main.java
public static boolean IsFormCompleted(ViewGroup v) { for (int i = 0; i < v.getChildCount(); i++) { Object child = v.getChildAt(i); if (child instanceof EditText) { EditText e = (EditText) child; if (e.getText().length() == 0) return false; } else if (child instanceof RadioGroup) { RadioGroup rb = (RadioGroup) child; if (rb.getCheckedRadioButtonId() < 0) return false; }/*from w ww. j av a 2 s. c om*/ } return true; }
From source file:com.booksaround.me.title.util.ViewUtil.java
/** * get id of checked radio buttion/*from ww w . j av a 2 s . co m*/ * @param root * @param resId is id of RadioGroup * @return */ public static int getIdOfRadioChecked(View root, int resId) { RadioGroup group = (RadioGroup) root.findViewById(resId); if (group == null) { throw new RuntimeException("View not found id=" + resId); } return group.getCheckedRadioButtonId(); }
From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java
public static String getTextOfView(View view) { Object textObj = null;//from w w w . j a va 2 s.c o m if (view instanceof TextView) { textObj = ((TextView) view).getText(); if (view instanceof Switch) { boolean isOn = ((Switch) view).isChecked(); textObj = isOn ? "1" : "0"; } } else if (view instanceof Spinner) { Object selectedItem = ((Spinner) view).getSelectedItem(); if (selectedItem != null) { textObj = selectedItem.toString(); } } else if (view instanceof DatePicker) { DatePicker picker = (DatePicker) view; int y = picker.getYear(); int m = picker.getMonth(); int d = picker.getDayOfMonth(); textObj = String.format("%04d-%02d-%02d", y, m, d); } else if (view instanceof TimePicker) { TimePicker picker = (TimePicker) view; int h = picker.getCurrentHour(); int m = picker.getCurrentMinute(); textObj = String.format("%02d:%02d", h, m); } else if (view instanceof RadioGroup) { RadioGroup radioGroup = (RadioGroup) view; int checkedId = radioGroup.getCheckedRadioButtonId(); int childCount = radioGroup.getChildCount(); for (int i = 0; i < childCount; i++) { View child = radioGroup.getChildAt(i); if (child.getId() == checkedId && child instanceof RadioButton) { textObj = ((RadioButton) child).getText(); break; } } } else if (view instanceof RatingBar) { RatingBar bar = (RatingBar) view; float rating = bar.getRating(); textObj = String.valueOf(rating); } return textObj == null ? "" : textObj.toString(); }
From source file:com.partypoker.poker.engagement.reach.activity.EngagementPollActivity.java
/** Enable action button if all choices selected. Disable otherwise. */ private void updateActionState() { boolean checked = true; for (RadioGroup group : mRadioGroups) checked &= group.getCheckedRadioButtonId() != -1; mActionButton.setEnabled(checked);/*from w ww. j a v a 2 s . c om*/ }
From source file:com.mycodehurts.rapidmath.app.SelectTestType.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.activity_select_test, container, false); //TextView textView = (TextView) rootView.findViewById(R.id.section_label); //textView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER))); Button btnStartTest = (Button) rootView.findViewById(R.id.btnStartTest); btnStartTest.setOnClickListener(new View.OnClickListener() { @Override/*from w ww. j a va 2s. com*/ public void onClick(View view) { RadioGroup chkSex = (RadioGroup) rootView.findViewById(R.id.testDifficultLevel); if (chkSex.getCheckedRadioButtonId() == -1) { } int iLevel = -1; if (chkSex.getCheckedRadioButtonId() == R.id.testEasy) iLevel = 0; else if (chkSex.getCheckedRadioButtonId() == R.id.testMedium) iLevel = 1; else if (chkSex.getCheckedRadioButtonId() == R.id.testDifficult) iLevel = 2; CheckBox enableTimer = (CheckBox) rootView.findViewById(R.id.enableTimer); Intent intent = new Intent(rootView.getContext(), TestActivity.class); intent.putExtra("iLevel", iLevel); intent.putExtra("enableTimer", enableTimer.isChecked() ? 1 : 0); startActivity(intent); } }); return rootView; }
From source file:com.example.android.lnotifications.VisibilityMetadataFragment.java
/** * Returns a {@link NotificationVisibility} depending on which RadioButton in the radiogroup * is selected.// w w w.ja v a2 s . co m * * @param radiogroup The RadioGroup. * @return The instance of {@link NotificationVisibility} corresponding to RadioButton. */ private NotificationVisibility getVisibilityFromSelectedRadio(RadioGroup radiogroup) { switch (radiogroup.getCheckedRadioButtonId()) { case R.id.visibility_public_radio_button: return NotificationVisibility.PUBLIC; case R.id.visibility_private_radio_button: return NotificationVisibility.PRIVATE; case R.id.visibility_secret_radio_button: return NotificationVisibility.SECRET; default: //If not selected, returns PUBLIC as default. return NotificationVisibility.PUBLIC; } }
From source file:com.aniruddhc.acemusic.player.WelcomeActivity.GooglePlayMusicFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContext = getActivity().getApplicationContext(); mApp = (Common) mContext;/* ww w .ja v a 2 s .c o m*/ View rootView = (View) inflater.inflate(R.layout.fragment_welcome_screen_5, null); welcomeHeader = (TextView) rootView.findViewById(R.id.welcome_header); welcomeHeader.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Light")); welcomeText1 = (TextView) rootView.findViewById(R.id.welcome_text_1); welcomeText1.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular")); googlePlayMusicDisclaimer = (TextView) rootView.findViewById(R.id.google_play_music_disclaimer); googlePlayMusicDisclaimer.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular")); radioGroup = (RadioGroup) rootView.findViewById(R.id.google_play_music_radio_group); final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext()); final Account[] accounts = accountManager.getAccountsByType("com.google"); final int size = accounts.length + 1; //We're adding 1 here to account (no pun intended) for the extra "Don't use Google Play Music" option. final RadioButton[] radioButton = new RadioButton[size]; //Add a new radio button the group for each username. for (int i = 0; i < size; i++) { radioButton[i] = new RadioButton(getActivity()); radioGroup.addView(radioButton[i]); //The first radio button will always be "Don't use Google Play Music". if (i == 0) { radioButton[i].setChecked(true); radioButton[i].setText(R.string.dont_use_google_play_music); } else { radioButton[i].setText(accounts[i - 1].name); } radioButton[i].setTag(i); radioButton[i].setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular")); } radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int radioButtonID = group.getCheckedRadioButtonId(); View radioButton = group.findViewById(radioButtonID); int index = group.indexOfChild(radioButton); if (index != 0) { account = accounts[index - 1]; mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name) .commit(); AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, getActivity(), true, account.name); task.execute(); } else { mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", "").commit(); mApp.getSharedPreferences().edit().putBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false).commit(); } } }); return rootView; }
From source file:com.afwsamples.testdpc.AddAccountActivity.java
@Override public void onNavigateNext() { RadioGroup addAccountOptions = (RadioGroup) findViewById(R.id.add_account_options); switch (addAccountOptions.getCheckedRadioButtonId()) { case R.id.add_account: addAccount(null);/* w ww . ja v a2 s . c om*/ break; case R.id.add_account_with_name: final View view = getLayoutInflater().inflate(R.layout.simple_edittext, null); new AlertDialog.Builder(this).setTitle(R.string.add_account_dialog_title).setView(view) .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { EditText editText = (EditText) view.findViewById(R.id.input); String accountName = editText.getText().toString(); addAccount(accountName); }).show(); break; case R.id.add_account_skip: if (mNextActivityIntent != null) { mNextActivityIntent.putExtra(EnableProfileActivity.EXTRA_ENABLE_PROFILE_NOW, true); startActivity(mNextActivityIntent); } finish(); break; } }
From source file:myawesomepackagename.codelabandroidwear.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Custom Title and Message for custom Notification mCustomTitle = (EditText) findViewById(R.id.notificationTitle); mCustomMessage = (EditText) findViewById(R.id.notificationMessage); // RadioGroup for the customIcon mCustomIconGroup = (RadioGroup) findViewById(R.id.iconGroup); mCustomIconGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { // The name of the ICONS will change based on how you named it.... @Override//from w w w . j a va2s . co m public void onCheckedChanged(RadioGroup group, int checkedId) { switch (group.getCheckedRadioButtonId()) { case R.id.icon1: mCustomIcon = R.drawable.ic_wear_notification; break; case R.id.icon2: mCustomIcon = R.drawable.ic_notification_2; break; case R.id.icon3: mCustomIcon = R.drawable.ic_notification3; break; } } }); // RadioGroup to determine if App Icons should be shown or not. showHideIconGroup = (RadioGroup) findViewById(R.id.hideIconGroup); showHideIconGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (group.getCheckedRadioButtonId()) { case R.id.showIcon: showIcon = true; break; case R.id.hideIcon: showIcon = false; break; } } }); }
From source file:com.conferenceengineer.android.iosched.ui.SessionFeedbackFragment.java
int getCheckedRadioIndex(RadioGroup rg) { int radioId = rg.getCheckedRadioButtonId(); View rb = rg.findViewById(radioId); return rg.indexOfChild(rb); }