android RadioGroup和RadioB… 分类: Android开发 2014-05-30 10:58 75人阅读 评论(0) 收藏

  <RadioGroup
    android:id="@+id/myRadioGroup"
    android:layout_width="137px"
    android:layout_height="216px"
    android:orientation="vertical"
    android:layout_x="3px"
    android:layout_y="54px"
    >
    
    <RadioButton
      android:id="@+id/myRadioButton1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/tr_radio_op1"
    />
        <RadioButton
      android:id="@+id/myRadioButton2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/tr_radio_op2"
    />
    </RadioGroup> 

 

 

 

public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   
    mTextView1 = (TextView) findViewById(R.id.myTextView);
    mRadioGroup1 = (RadioGroup) findViewById(R.id.myRadioGroup);
    mRadio1 = (RadioButton) findViewById(R.id.myRadioButton1);
    mRadio2 = (RadioButton) findViewById(R.id.myRadioButton2);
   
    mRadioGroup1.setOnCheckedChangeListener(mChangeRadio);
    }
  private RadioGroup.OnCheckedChangeListener mChangeRadio =
    new RadioGroup.OnCheckedChangeListener()
  {
    @Override public void onCheckedChanged(RadioGroup group, int checkedId)
    {
      // TODO Auto-generated method stub
      if(checkedId==mRadio1.getId())
      {
       
        mTextView1.setText(mRadio1.getText());
        }
      else if(checkedId==mRadio2.getId())
      {
       
        mTextView1.setText(mRadio2.getText());
        }
      }
    };

posted @ 2014-05-30 10:58  leansmall  阅读(81)  评论(0编辑  收藏  举报