下面列出了android.widget.RadioGroup#OnCheckedChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initView() {
pg = new ProgressDialog(Activity_UpdateAddress.this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("添加地址");
TextView toolbarText = (TextView) findViewById(R.id.toolbar_text);
toolbarText.setText("");
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
findViewById();
btn_submitAddress.setOnClickListener(this);
//为radioGroup绑定监听器
radioGroup.setOnCheckedChangeListener(changeListener);
changeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int id = group.getCheckedRadioButtonId();//获取选中按钮的id
switch (id) {
case R.id.rb_male://男
Toast.makeText(Activity_UpdateAddress.this, rb_male.getText(), Toast.LENGTH_SHORT).show();
Sex = "男";
break;
case R.id.rb_female://女
Sex = "女";
break;
default:
break;
}
}
};
}
@NonNull
private FrameLayout createRadioGroupLayout(final String[] typeList, RadioGroup.OnCheckedChangeListener listener) {
final List<RadioButton> rbList = new ArrayList<>();
final RadioGroup radioGroup = new RadioGroup(this);
radioGroup.setPadding(24, 24, 24, 24);
for (int i = 0; i < typeList.length; i++) {
RadioButton rb = new RadioButton(this);
rb.setText(typeList[i]);
rbList.add(rb);
radioGroup.addView(rb);
}
String curType = mFeedbackTypeTxt.getText().toString();
for (RadioButton btn : rbList) {
if (btn.getText().toString().equals(curType)) {
radioGroup.check(btn.getId());
}
}
radioGroup.setOnCheckedChangeListener(listener);
FrameLayout frameLayout = new FrameLayout(this);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
lp.leftMargin = DimenUtil.dip2px(this, 24);
lp.rightMargin = lp.leftMargin;
frameLayout.addView(radioGroup, lp);
return frameLayout;
}
@Bindable
public RadioGroup.OnCheckedChangeListener getShapeWatcher() {
return (group, checkedId) -> setShape(mapShape(checkedId));
}
@Bindable
public RadioGroup.OnCheckedChangeListener getBackgroundWatcher() {
return (group, checkedId) -> setBackground(mapColor(checkedId));
}
public static Void onCheckedChange(RadioGroup.OnCheckedChangeListener arg) {
return BaseDSL.attr("onCheckedChange", arg);
}
public static Void onCheckedChange(RadioGroup.OnCheckedChangeListener arg) {
return BaseDSL.attr("onCheckedChange", arg);
}
/**
* 设置switchbutton 状态变更监听器
*
* @param onCheckedChangeListener
*/
public void setOnCheckedChangeListener(RadioGroup.OnCheckedChangeListener onCheckedChangeListener) {
segmentedGroup.setOnCheckedChangeListener(onCheckedChangeListener);
}