最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)之獲取單選與復(fù)選框的值操作示例

 更新時間:2019年04月05日 12:12:16   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)之獲取單選與復(fù)選框的值操作,結(jié)合實例形式分析了Android針對單選按鈕、復(fù)選框的事件響應(yīng)、數(shù)值獲取等相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)之獲取單選與復(fù)選框的值操作。分享給大家供大家參考,具體如下:

效果圖:

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/root"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <TableRow>
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="性別"/>
    <!--定義一組單選按鈕-->
    <RadioGroup
      android:id="@+id/rg"
      android:orientation="horizontal"
      android:layout_gravity="center_horizontal">
      <!--定義兩個單選按鈕-->
      <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/male"
        android:text="男"
        android:checked="false"/>
      <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/female"
        android:text="女"
        android:checked="false"/>
    </RadioGroup>
  </TableRow>
  <TableRow>
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="喜歡的顏色"/>
    <!--定義一個垂直線性布局-->
    <LinearLayout
      android:layout_gravity="center_horizontal"
      android:orientation="vertical"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
      <!--定義三個復(fù)選框-->
      <CheckBox
        android:id="@+id/color_red"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="紅色"/>
      <CheckBox
        android:id="@+id/color_blue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="藍(lán)色"/>
      <CheckBox
        android:id="@+id/color_green"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="綠色"/>
    </LinearLayout>
  </TableRow>
  <TextView
    android:id="@+id/show_sex"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
  <Button
    android:id="@+id/show"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="顯示復(fù)選框內(nèi)容"
    android:textSize="20pt"/>
  <TextView
    android:id="@+id/show_color"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
</TableLayout>

Java代碼:

public class Home extends AppCompatActivity {
  RadioGroup radioGroup01 ;
  TextView textView01 ;
  TextView textView02 ;
  Button button01 ;
  CheckBox checkBox01 ;
  CheckBox checkBox02 ;
  CheckBox checkBox03 ;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);//顯示manLayout
    //連接組建
    radioGroup01 = (RadioGroup) findViewById(R.id.rg);
    textView01 = (TextView) findViewById(R.id.show_sex);
    textView02 = (TextView) findViewById(R.id.show_color);
    checkBox01 = (CheckBox) findViewById(R.id.color_red);
    checkBox02 = (CheckBox) findViewById(R.id.color_blue);
    checkBox03 = (CheckBox) findViewById(R.id.color_green);
    button01 = (Button) findViewById(R.id.show);
    //添加監(jiān)聽事件
    radioGroup01.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(RadioGroup group, int checkedId) {
        //根據(jù)用戶勾選信息改變tip字符串的值
        String tip = checkedId == R.id.male ?
        "您的性別為男" : "您的性別為n女" ;
        //修改show組件文本
        textView01.setText(tip);
      }
    });
    //輸出按鈕監(jiān)聽事件
    button01.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        textView02.setText("喜歡的顏色: \n");
        //篩選復(fù)選框信息
        StringBuffer stringBuffer01 = new StringBuffer();
        stringBuffer01.append(textView02.getText().toString());
        if (checkBox01.isChecked()) {
          stringBuffer01.append("紅色\n");
        }
        if (checkBox02.isChecked()) {
          stringBuffer01.append("藍(lán)色\n");
        }
        if (checkBox03.isChecked()) {
          stringBuffer01.append("綠色");
        }
        textView02.setText(stringBuffer01.toString());
      }
    });
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》及《Android資源操作技巧匯總

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • Android中的Handler與多線程應(yīng)用實例

    Android中的Handler與多線程應(yīng)用實例

    這篇文章主要介紹了Android中的Handler與多線程應(yīng)用實例,本文首先解釋一下handler是用來干嘛的,然后通過例子介紹其在多線程中的應(yīng)用,需要的朋友可以參考下
    2015-03-03
  • Jetpack?Compose常用組件詳細(xì)介紹

    Jetpack?Compose常用組件詳細(xì)介紹

    本篇開始介紹Jetpack?Compose?中常用的組件。有一部分之前的文章中也出現(xiàn)過,今天詳細(xì)說明一下
    2022-10-10
  • android 檢查網(wǎng)絡(luò)連接狀態(tài)實現(xiàn)步驟

    android 檢查網(wǎng)絡(luò)連接狀態(tài)實現(xiàn)步驟

    android 如何檢查網(wǎng)絡(luò)連接狀態(tài),是android開發(fā)中一個常見的問題,本文將介紹如何實現(xiàn),需要的朋友可以參考下
    2012-12-12
  • Android里實現(xiàn)退出主程序的提示代碼

    Android里實現(xiàn)退出主程序的提示代碼

    當(dāng)用戶選擇"確定",就退出當(dāng)前的對話框。其中,有個很重要的函數(shù),Activity.finish(),通過調(diào)用這個函數(shù),退出當(dāng)前運(yùn)行的整個Android程序
    2013-06-06
  • 利用Jetpack Compose繪制可愛的天氣動畫

    利用Jetpack Compose繪制可愛的天氣動畫

    Jetpack Compose是用于構(gòu)建原生Android UI的現(xiàn)代工具包。Jetpack Compose使用更少的代碼,強(qiáng)大的工具和直觀的Kotlin API,簡化并加速了Android上的UI開發(fā)。本文將利用Jetpack Compose繪制可愛的天氣動畫,感興趣的可以了解一下
    2022-01-01
  • Android滑動沖突的解決技巧

    Android滑動沖突的解決技巧

    Android滑動沖突是Android開發(fā)中常見的問題,在一個界面中,可能存在多個View可以響應(yīng)滑動事件,如果這些View滑動方向一致,則會導(dǎo)致滑動沖突,本文將從原理、使用與優(yōu)化三個方面,詳細(xì)介紹Android滑動沖突的解決方式,需要的朋友可以參考下
    2024-01-01
  • Android退出應(yīng)用最優(yōu)雅的方式(改進(jìn)版)

    Android退出應(yīng)用最優(yōu)雅的方式(改進(jìn)版)

    這篇文章主要介紹了Android退出應(yīng)用最優(yōu)雅的方式,改進(jìn)版,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Android使用ftp方式實現(xiàn)文件上傳和下載功能

    Android使用ftp方式實現(xiàn)文件上傳和下載功能

    這篇文章主要介紹了Android使用ftp方式實現(xiàn)文件上傳和下載功能,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-06-06
  • 深入Android Browser配置管理的詳解

    深入Android Browser配置管理的詳解

    本篇文章是對Android Browser的配置管理進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Android中EditText setText方法的踩坑實戰(zhàn)

    Android中EditText setText方法的踩坑實戰(zhàn)

    這篇文章主要給大家分享了一些關(guān)于Android中EditText setText方法的踩坑記錄,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07

最新評論

潼关县| 丹寨县| 临夏市| 长丰县| 芮城县| 新安县| 南昌县| 南江县| 武义县| 班戈县| 紫金县| 伊金霍洛旗| 长子县| 五华县| 特克斯县| 平凉市| 巴彦淖尔市| 中江县| 宕昌县| 阳高县| 达拉特旗| 临沂市| 罗平县| 上栗县| 桃江县| 泰来县| 大竹县| 泰顺县| 九龙县| 北川| 原平市| 小金县| 东宁县| 荆门市| 东乌珠穆沁旗| 上思县| 南宁市| 贵溪市| 花莲市| 兴安县| 绥德县|