一、RadioBox单选框的使用

 

public RadioGroup mRadioGroup1;
	public RadioButton mRadio1, mRadio2;
	public Button button1;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.radio);
		button1 = (Button) findViewById(R.id.button1);
		mRadioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
		mRadio1 = (RadioButton) findViewById(R.id.radio1);
		mRadio2 = (RadioButton) findViewById(R.id.radio2);
		/* RadioGroup用OnCheckedChangeListener来执行 */
		mRadioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub
				if (checkedId == mRadio1.getId()) {
					/* 把mRadio1的内容传到mTextView1 */
					toast(mRadio1.getText().toString());
				} else if (checkedId == mRadio2.getId()) {
					/* 把mRadio2的内容传到mTextView1 */
					toast(mRadio2.getText().toString());
				}
			}
		});
		
		button1.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				mRadioGroup1.clearCheck();
			}
			
		});
	}

	public void toast(String str) {
		Toast.makeText(RadioBoxNew.this, str, Toast.LENGTH_LONG).show();
	}
 


RadioBox单选框应用
 
RadioBox单选框应用

相关文章:

  • 2021-12-05
  • 2021-11-01
  • 2022-01-14
  • 2021-06-14
  • 2022-01-21
  • 2022-12-23
  • 2021-09-14
  • 2021-12-16
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
相关资源
相似解决方案