Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android RadioButton单选框的使用方法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。


public class MainActivity extends Activity {

 public RadioGroup mRadioGroup1;
 public RadioButton mRadio1,mRadio2;

 @Override
 protected void onCreate(Bundle savedInstanceStatE) {
  super.onCreate(savedInstanceStatE);
  setContentView(R.layout.activity_main);

  mRadioGroup1 = (RadioGroup) findViewById(R.id.gendergroup);
  mRadio1 = (RadioButton) findViewById(R.id.girl);
  mRadio2 = (RadioButton) findViewById(R.id.boy);
  mRadioGroup1.setOncheckedchangelistener(radiogpchangE);

 }

 private RadioGroup.Oncheckedchangelistener radiogpchange = new RadioGroup.oncheckedchangelistener() {
  @Override
  public void oncheckedChanged(RadioGroup group,int checkedId) {
   if (checkedId == mRadio1.getId()) {
    Toast.makeText(getApplicationContext(),"女孩",1).show();
   } else if (checkedId == mRadio2.getId()) {
    Toast.makeText(getApplicationContext(),"男孩",1).show();
   }
  }
 };
}


RadioButton:就像是C#中的Radio控件,可以为控件设置Group,每个Group中的项只能选择一项;

    <RadioGroup

        android:id="@+id/gendergroup"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:orientation="vertical" >

        <RadioButton

            android:id="@+id/girl"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:text="@String/girl" />

        <RadioButton

            android:id="@+id/boy"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:text="@String/boy" />

    </RadioGroup>

大佬总结

以上是大佬教程为你收集整理的Android RadioButton单选框的使用方法全部内容,希望文章能够帮你解决Android RadioButton单选框的使用方法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。