使用RadioGroup怎么實(shí)現(xiàn)單選框的多行排列

使用RadioGroup怎么實(shí)現(xiàn)單選框的多行排列?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

為礦區(qū)等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及礦區(qū)網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)、礦區(qū)網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!

1.xml中的布局:

<RelativeLayout
  android:id="@+id/main_tab_container"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:paddingTop="30dp">

  <RadioGroup
   android:id="@+id/radio1"
   android:layout_width="match_parent"
   android:layout_height="60dp"
   android:layout_margin="5dp"
   android:orientation="horizontal">

   <RadioButton
    android:id="@+id/rb_1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="GBP英鎊" />

   <RadioButton
    android:id="@+id/rb_2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="HKD港元" />

   <RadioButton
    android:id="@+id/rb_3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="USD美元?" />
  </RadioGroup>

  <RadioGroup
   android:id="@+id/radio2"
   android:layout_width="match_parent"
   android:layout_height="60dp"
   android:layout_below="@+id/radio1"
   android:layout_margin="5dp"
   android:orientation="horizontal">

   <RadioButton
    android:id="@+id/rb_4"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="CHF瑞士法郎" />

   <RadioButton
    android:id="@+id/rb_5"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="SGD新加坡元" />

   <RadioButton
    android:id="@+id/rb_6"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="SEK瑞典克朗" />
  </RadioGroup>

  <RadioGroup
   android:id="@+id/radio3"
   android:layout_width="match_parent"
   android:layout_height="60dp"
   android:layout_below="@+id/radio2"
   android:layout_margin="5dp"
   android:orientation="horizontal">

   <RadioButton
    android:id="@+id/rb_7"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="JPY日元" />

   <RadioButton
    android:id="@+id/rb_8"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="CAD加拿大元?" />

   <RadioButton
    android:id="@+id/rb_9"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="@dimen/RB_text_size"
    android:text="AUD澳大利亞元" />
  </RadioGroup>

  <RadioGroup
   android:id="@+id/radio4"
   android:layout_width="match_parent"
   android:layout_height="60dp"
   android:layout_below="@+id/radio3"
   android:layout_margin="5dp"
   android:orientation="horizontal">

   <RadioButton
    android:id="@+id/rb_10"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="@dimen/RB_text_size"
    android:text="EOR歐元?" />

  </RadioGroup>

</RelativeLayout>

這樣就實(shí)現(xiàn)了多行布局,這只是我布局中的一部分,其中 android:textSize=”@dimen/RB_text_size” 為自己定義的字體大小.

2.activity中的使用以及處理:

public class SelectMoneyActivity extends BaseActivity {


 String strBtnSelected = ""; //記錄選擇的是哪個(gè)選項(xiàng)

 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);

//創(chuàng)建監(jiān)聽(tīng)器,為每個(gè)RadioButton注冊(cè)監(jiān)聽(tīng)

  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);


//點(diǎn)擊事件的監(jiān)聽(tīng)器
 public class BtnSelected implements View.OnClickListener {

  private String btnId;

  public BtnSelected(String str) {
   btnId = str;
  }

  @Override
  public void onClick(View v) {
   strBtnSelected = btnId;  //選擇的某一項(xiàng)
   isSelect = true;
   //點(diǎn)擊了第一行 ,就把另外行的點(diǎn)擊項(xiàng)清空
   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();
   }
  }
 }
}

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。

名稱欄目:使用RadioGroup怎么實(shí)現(xiàn)單選框的多行排列
轉(zhuǎn)載來(lái)于:http://muchs.cn/article8/ijccop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管響應(yīng)式網(wǎng)站、網(wǎng)站內(nèi)鏈、網(wǎng)頁(yè)設(shè)計(jì)公司、網(wǎng)站營(yíng)銷商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化