欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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加殼過程中mprotect調(diào)用失敗的原因分析

    解決Android加殼過程中mprotect調(diào)用失敗的原因分析

    本文探討的主要內(nèi)容是mprotect調(diào)用失敗的根本原因,以及在加殼實現(xiàn)中的解決方案,通過本文的闡述,一方面能夠幫助遇到同類問題的小伙伴解決心中的疑惑,另一方面能夠給大家提供可落地的實現(xiàn)方案,需要的朋友可以參考下
    2022-01-01
  • 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)示例

    這篇文章主要介紹了Android 畫中畫模式的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • 基于Fedora14下自帶jdk1.6版本 安裝jdk1.7不識別的解決方法

    基于Fedora14下自帶jdk1.6版本 安裝jdk1.7不識別的解決方法

    本篇文章是對Fedora14下自帶jdk1.6版本,安裝jdk1.7不識別的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Android 屏蔽和捕獲Home鍵的示例代碼

    Android 屏蔽和捕獲Home鍵的示例代碼

    本文主要介紹 Android 屏蔽和捕獲Home 鍵的方法,并附有代碼實例參考,在開發(fā)過程中可能會遇到這樣的功能,有需要的同學(xué)可以參考下
    2016-07-07
  • Kotlin的枚舉與異常示例詳解

    Kotlin的枚舉與異常示例詳解

    這篇文章主要給大家介紹了關(guān)于Kotlin的枚舉與異常的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Kotlin具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • Android 選擇相冊照片并返回功能的實現(xiàn)代碼

    Android 選擇相冊照片并返回功能的實現(xiàn)代碼

    這篇文章主要介紹了Android 從相冊中選擇照片并返回功能,需要的朋友可以參考下
    2018-03-03
  • Jetpack Compose圖片組件使用實例詳細(xì)講解

    Jetpack Compose圖片組件使用實例詳細(xì)講解

    在Compose中,圖片組件主要有兩種,分別是顯示圖標(biāo)的Icon組件和顯示圖片的Image組件,當(dāng)我們顯示一系列的小圖標(biāo)的時候,我們可以使用Icon組件,當(dāng)顯示圖片時,我們就用專用的Image組件
    2023-04-04
  • Flutter實現(xiàn)懸浮分組列表功能

    Flutter實現(xiàn)懸浮分組列表功能

    這篇文章主要介紹了Flutter-實現(xiàn)懸浮分組列表,我們將介紹如何使用 Flutter 實現(xiàn)一個帶有分組列表的應(yīng)用程序,我們將通過 CustomScrollView 和 Sliver 組件來實現(xiàn)該功能,需要的朋友可以參考下
    2024-08-08
  • Android 開發(fā)訂單流程view實例詳解

    Android 開發(fā)訂單流程view實例詳解

    這篇文章主要介紹了 Android 開發(fā)訂單流程view實例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03

最新評論