@Override public void onClick(View v) { RadioButton rb = (RadioButton)v; switch (rb.getId()) { case R.id.rbtnRussian: break; case R.id.rbtnEnglish: break; case R.id.rbtnSpanish: break; default: break; } } };
@Override public void addView(View child, int index, ViewGroup.LayoutParams params) { if (child instanceof RadioButton) { final RadioButton button = (RadioButton) child; if (button.isChecked()) { mProtectFromCheckedChange = true; if (mCheckedId != -1) { setCheckedStateForView(mCheckedId, false); } mProtectFromCheckedChange = false; setCheckedId(button.getId()); } } super.addView(child, index, params); }
@Test public void shouldInformRadioGroupThatItIsChecked() throws Exception { RadioButton radioButton1 = new RadioButton(context); radioButton1.setId(99); RadioButton radioButton2 = new RadioButton(context); radioButton2.setId(100); RadioGroup radioGroup = new RadioGroup(context); radioGroup.addView(radioButton1); radioGroup.addView(radioButton2); radioButton1.setChecked(true); assertThat(radioGroup.getCheckedRadioButtonId()).isEqualTo(radioButton1.getId()); radioButton2.setChecked(true); assertThat(radioGroup.getCheckedRadioButtonId()).isEqualTo(radioButton2.getId()); }
public void onClick(View v) { RadioButton btn = (RadioButton) v; Question question = questionList.get(position); question.unselectAll(); // unselects all Answer's question.getAnswer(btn.getId()).setSelected(true); }
@Override public void onClick(View v) { checkButton(buttons, options, button.getId(), activity); } });
@Override public void onClick(View v) { checkButton(buttons, options, button.getId(), activity); } });
@Override public void onClick(View v) { checkButton(buttons, options, button.getId(), context); } });
@Override public void onClick(View v) { checkButton(buttons, options, button.getId(), context); } });
RadioButton radioLeakTightYes = (RadioButton) findViewById(...); RadioButton radioLeakTightNo = (RadioButton) findViewById(...); radioGroupLeakTight.clearCheck(); if(currentTask.isLeakTight()){ radioGroupLeakTight.check(radioLeakTightYes.getId()); } else { radioGroupLeakTight.check(radioLeakTightNo.getId()); }
private void load() { SharedPreferences sharedPreferences = getPreferences(Context.MODE_PRIVATE); for(int i=0;i<radioGroup.getChildCount();i++){ RadioButton rbtn=(RadioButton)radioGroup.getChildAt(i); rbtn.setChecked(sharedPreferences.getBoolean("check"+rbtn.getId(), false)); } }
final ArrayList<RadioButton> mGroup = new ArrayList<RadioButton>(); CompoundButton.OnCheckedChangeListener mListener = new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { for(RadioButton btn : mGroup) { if (buttonView.getId() != btn.getId() && isChecked) { btn.setChecked(false); } } } };
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { for (int i = 0; i < group.getChildCount(); i++) { RadioButton child = (RadioButton) group.getChildAt(i); child.setChecked(child.getId() == checkedId); if (child.getId() == checkedId) selectedPreference = (String) child.getTag(); } } });
@Override public void onCheckedChanged(RadioGroup radioGroup, int btnId) { if (null != itemListener){ for (int i=0; i<rbList.size(); i++){ if (rbList.get(i).getId() == btnId){ itemListener.onItemClick(i); break; } } } dismiss(); }
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == rb1.getId()) { addpsTv.setText(rb1.getText().toString()); alertDialog.dismiss(); } else { Toast.makeText(getContext(), "not support", Toast.LENGTH_SHORT).show(); } } });
private void handleSearch() { final String inputString = mEditText.getText().toString().trim().replaceAll("\\n", ""); if (mSearchRadio.getCheckedRadioButtonId() == mSearchName.getId()) {//用户名 searchName(inputString); } else { searchId(inputString); } }
private void handleSearch() { final String inputString = mEditText.getText().toString(); if (mSearchRadio.getCheckedRadioButtonId() == mUserTopicButton.getId()) {//用户主题 searchUserTopic(inputString); } else if (mSearchRadio.getCheckedRadioButtonId() == mUserReplyButton.getId()) {//用户回复 searchUserReply(inputString); } else if (mSearchRadio.getCheckedRadioButtonId() == mTopicButton.getId()) { searchTopic(inputString); } else { searchAllTopic(inputString); } }
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { for (int i = 0; i < group.getChildCount(); i++) { RadioButton rb = (RadioButton) group.getChildAt(i); if (rb.getId() == checkedId) { type[0] = rb.getText().toString(); } } } });
@Override public void onClick(View v) { final RadioButton selectedButton = findViewById(radioGroup.getCheckedRadioButtonId()); if (v instanceof RadioButton && eventHandler != null && selectedButton != null) { eventHandler.onClick(selectedButton.getId() - radioGroup.getId() - 1); } closeDialog(); } }