原文地址:androidRadioGroup和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());
}
}
};

更多相关文章

  1. android googlemap的location报空指针解决案例
  2. ndk 历史版本下载
  3. android滑动删除的一个开源项目SwipeDelMenuLayout的简单使用
  4. 10个经典的Android开源应用项目
  5. android短信监听
  6. 10个经典的Android开源应用项目
  7. 10个经典的Android开源应用项目
  8. Android牟利之道(二)--广告平台的介绍
  9. 10个经典的Android开源应用项目

随机推荐

  1. Android实现图文混排的笔记·终篇
  2. Android(安卓)RxJava:图文详解 变换操作符
  3. Android(安卓)实现通话监听
  4. Android初体验
  5. android中轮播图的实现
  6. [开源c-FFMpeg]Android(安卓)add prebuil
  7. 移动开发参考书之Android篇
  8. Android内核详解之Low memory killer
  9. android ImageView 几点总结
  10. UiAutomator通过ant实现快速调试