List of usage examples for android.widget RadioGroup findViewById
@Nullable public final <T extends View> T findViewById(@IdRes int id)
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;/*from w w w . j a 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.conferenceengineer.android.iosched.ui.SessionFeedbackFragment.java
int getCheckedRadioIndex(RadioGroup rg) { int radioId = rg.getCheckedRadioButtonId(); View rb = rg.findViewById(radioId); return rg.indexOfChild(rb); }
From source file:com.github.johnpersano.supertoasts.demo.fragments.AttributeRadioGroupFragment.java
@Nullable @Override// ww w .j a va 2 s. c o 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.partypoker.poker.engagement.reach.activity.EngagementPollActivity.java
@Override protected void onAction() { /* Scan U.I radio button states */ LinearLayout questionsLayout = getView("questions"); JSONArray questions = mContent.getQuestions(); try {/*from w w w . jav a 2 s. c o m*/ for (int i = 0; i < questions.length(); i++) { /* Get question */ JSONObject question = questions.getJSONObject(i); /* Get radio group by question */ String questionId = question.getString("id"); RadioGroup choicesView = (RadioGroup) questionsLayout.findViewWithTag(question); /* Get selected choice id */ int selectedViewId = choicesView.getCheckedRadioButtonId(); RadioButton selectedChoiceView = (RadioButton) choicesView.findViewById(selectedViewId); String choiceId = selectedChoiceView.getTag().toString(); /* Fill answer */ mContent.fillAnswer(questionId, choiceId); } } catch (JSONException jsone) { /* Won't happen */ } /* Submit answers */ mContent.actionContent(getApplicationContext()); }
From source file:com.boostcamp.hyeon.wallpaper.setting.view.SettingFragment.java
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { RadioButton radioButton = (RadioButton) group.findViewById(checkedId); if (radioButton == null) return;//from w w w .j ava 2s . c o m if (group.equals(mChangeRepeatCycleRadioGroup) && radioButton.isChecked()) { String value = radioButton.getText().toString(); int minute = value.indexOf(getString(R.string.label_minute)); int hour = value.indexOf(getString(R.string.label_hour)); if (minute != -1 && hour == -1) { mChangeCycle = Integer.valueOf(value.substring(0, minute)); mChangeCycle *= Define.MINUTE_CONVERT_TO_MILLIS; } else if (minute == -1 && hour != -1) { mChangeCycle = Integer.valueOf(value.substring(0, hour)); mChangeCycle *= Define.HOUR_CONVERT_TO_MILLIS; } else { mChangeCycle = Define.CHANGE_CYCLE_SCREEN_OFF; } Log.d(TAG, "change cycle: " + mChangeCycle); } }
From source file:com.physphil.android.unitconverterultimate.fragments.ConversionFragment.java
/** * Get the Unit associated with the checked button in a radio group * * @param group RadioGroup which contains the button * @return Unit associated with checked button *//*from ww w.java 2 s. c o m*/ private Unit getCheckedUnit(RadioGroup group) { int index = group.getCheckedRadioButtonId(); RadioButton btn = (RadioButton) group.findViewById(index); return (Unit) btn.getTag(); }
From source file:com.cw.litenote.config.Config.java
void selectStyleDialog(View view) { mContext = getActivity();/* w ww .ja v 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.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 {/*w ww . j a v a 2s . 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:org.openmrs.mobile.activities.formdisplay.FormDisplayPageFragment.java
private void setOnCheckedChangeListener(RadioGroup radioGroup, final SelectOneField radioGroupField) { radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override//from w w w . j a v a2 s . com public void onCheckedChanged(RadioGroup radioGroup, int i) { View radioButton = radioGroup.findViewById(i); int idx = radioGroup.indexOfChild(radioButton); radioGroupField.setAnswer(idx); } }); }
From source file:odoo.controls.OSelectionField.java
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { int index = mRadioGroup.indexOfChild(group.findViewById(checkedId)); ODataRow row = items.get(index);/*w w w . j a v a 2 s. c o m*/ setValue(row.getInt(OColumn.ROW_ID)); }