首页 > 其他 > 详细

RadioButton与监听

时间:2016-01-26 15:08:17      阅读:125      评论:0      收藏:0      [点我收藏+]

public class MainActivity extends Activity implements OnCheckedChangeListener {

 

<RadioGroup
  android:id="@+id/radGrp"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" >

<RadioButton
  android:id="@+id/rb1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="RadioButton1" />

实例:rb1 = (RadioButton) findViewById(R.id.rb1);

rg.setOnCheckedChangeListener(this);//将单选组绑定监听器

 


//重写监听器函数
/**
* @param group:指单选组
* @param group:指单选组中发生状态改变的RadioButton的内存ID!
*/
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
  if (group == rg) {//因为当前程序中只有一个RadioGroup,此步可以不进行判定
    String rbName = null;
  if (checkedId == rb1.getId()) {
    rbName = rb1.getText().toString();
  }
    Toast.makeText(this, "选择了下标为“" + rbName + "”的单选按钮",
    Toast.LENGTH_LONG).show();
  }
}

 

RadioButton与监听

原文:http://www.cnblogs.com/zhaoleigege/p/5160361.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!