您的位置:首页 > 移动开发 > Android开发

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

2014-05-30 10:58 741 查看
原文地址:RadioGroup和RadioButton">android RadioGroup和RadioButton作者:Android
<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());

}

}

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐