RadioGroup中怎么实现单选框的多行排列-创新互联
本篇文章给大家分享的是有关RadioGroup中怎么实现单选框的多行排列,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
创新互联建站是一家专注于做网站、网站建设与策划设计,密山网站建设哪家好?创新互联建站做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:密山等地区。密山做网站价格咨询:135182197921.xml中的布局:
这样就实现了多行布局,这只是我布局中的一部分,其中 android:textSize=”@dimen/RB_text_size” 为自己定义的字体大小.
2.activity中的使用以及处理:
public class SelectMoneyActivity extends BaseActivity { String strBtnSelected = ""; //记录选择的是哪个选项 private RadioGroup rg1, rg2, rg3, rg4; private RadioButton rb_1, rb_2, rb_3, rb_4, rb_5, rb_6, rb_7, rb_8, rb_9, rb_10; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select_money); initView(); } private void initView() { rg1 = (RadioGroup) findViewById(R.id.radio1); rg2 = (RadioGroup) findViewById(R.id.radio2); rg3 = (RadioGroup) findViewById(R.id.radio3); rg4 = (RadioGroup) findViewById(R.id.radio4); rb_1 = (RadioButton) findViewById(R.id.rb_1); rb_2 = (RadioButton) findViewById(R.id.rb_2); rb_3 = (RadioButton) findViewById(R.id.rb_3); rb_4 = (RadioButton) findViewById(R.id.rb_4); rb_5 = (RadioButton) findViewById(R.id.rb_5); rb_6 = (RadioButton) findViewById(R.id.rb_6); rb_7 = (RadioButton) findViewById(R.id.rb_7); rb_8 = (RadioButton) findViewById(R.id.rb_8); rb_9 = (RadioButton) findViewById(R.id.rb_9); rb_10 = (RadioButton) findViewById(R.id.rb_10); btn_back = (Button) findViewById(R.id.btn_back); btn_next = (Button) findViewById(R.id.btn_next);//创建监听器,为每个RadioButton注册监听 BtnSelected btnSelected1 = new BtnSelected("1"); BtnSelected btnSelected2 = new BtnSelected("2"); BtnSelected btnSelected3 = new BtnSelected("3"); BtnSelected btnSelected4 = new BtnSelected("4"); BtnSelected btnSelected5 = new BtnSelected("5"); BtnSelected btnSelected6 = new BtnSelected("6"); BtnSelected btnSelected7 = new BtnSelected("7"); BtnSelected btnSelected8 = new BtnSelected("8"); BtnSelected btnSelected9 = new BtnSelected("9"); BtnSelected btnSelected10 = new BtnSelected("10"); rb_1.setOnClickListener(btnSelected1); rb_2.setOnClickListener(btnSelected2); rb_3.setOnClickListener(btnSelected3); rb_4.setOnClickListener(btnSelected4); rb_5.setOnClickListener(btnSelected5); rb_6.setOnClickListener(btnSelected6); rb_7.setOnClickListener(btnSelected7); rb_8.setOnClickListener(btnSelected8); rb_9.setOnClickListener(btnSelected9); rb_10.setOnClickListener(btnSelected10);//点击事件的监听器 public class BtnSelected implements View.OnClickListener { private String btnId; public BtnSelected(String str) { btnId = str; } @Override public void onClick(View v) { strBtnSelected = btnId; //选择的某一项 isSelect = true; //点击了第一行 ,就把另外行的点击项清空 if (btnId.equals("1") || btnId.equals("2") || btnId.equals("3")) { rg2.clearCheck(); rg3.clearCheck(); rg4.clearCheck(); } else if (btnId.equals("4") || btnId.equals("5") || btnId.equals("6")) { rg1.clearCheck(); rg3.clearCheck(); rg4.clearCheck(); } else if (btnId.equals("7") || btnId.equals("8") || btnId.equals("9")) { rg1.clearCheck(); rg2.clearCheck(); rg4.clearCheck(); } else { rg1.clearCheck(); rg2.clearCheck(); rg3.clearCheck(); } } }}
以上就是RadioGroup中怎么实现单选框的多行排列,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。
网站栏目:RadioGroup中怎么实现单选框的多行排列-创新互联
标题URL:http://scyanting.com/article/dhpogs.html