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

Android單選按鈕RadioButton的使用詳解

 更新時(shí)間:2019年03月29日 09:20:36   作者:徐劉根  
今天小編就為大家分享一篇關(guān)于Android單選按鈕RadioButton的使用詳解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧

RadioButton是最普通的UI組件之一,繼承了Button類,可以直接使用Button支持的各種屬性和方法。

RadioButton與普通按鈕不同的是,它多了一個(gè)可以選中的功能,可額外指定一個(gè)android:checked屬性,該屬性可以指定初始狀態(tài)時(shí)是否被選中,其實(shí)也可以不用指定,默認(rèn)初始狀態(tài)都不選中。

使用RadioButton必須和單選框RadioGroup一起使用,在RadioGroup中放置RadioButton,通過setOnCheckedChangeListener( )來(lái)響應(yīng)按鈕的事件;

(1)選用radioGroup的圖標(biāo)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" >
  <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="44dp"
    android:text="性別:"
    android:textSize="20dp" />
  <RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/textView1"
    android:layout_marginLeft="21dp"
    android:layout_toRightOf="@+id/textView1"
    android:orientation="horizontal" >
    <RadioButton
      android:id="@+id/radio0"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:checked="true"
      android:onClick="onRadioButtonClicked"
      android:text="男" />
    <RadioButton
      android:id="@+id/radio1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:onClick="onRadioButtonClicked"
      android:text="女" />
    <RadioButton
      android:id="@+id/radio2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:onClick="onRadioButtonClicked"
      android:text="保密" />
  </RadioGroup>
</RelativeLayout>

(2)控制的類是

package com.lc.radiobutton;
import com.example.radiobutton.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;
public class MainActivity extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
 /*
 * 設(shè)置radio的點(diǎn)擊事件,當(dāng)點(diǎn)擊的時(shí)候顯示文字
 */
 public void onRadioButtonClicked(View view) {
 RadioButton button = (RadioButton) view;
 boolean isChecked = button.isChecked();
 switch (view.getId()) {
 case R.id.radio0:
  if (isChecked) {
  Toast.makeText(MainActivity.this, button.getText(), 1).show();
  }
  break;
 case R.id.radio1:
  if (isChecked) {
  Toast.makeText(MainActivity.this, button.getText(), 1).show();
  }
  break;
 case R.id.radio2:
  if (isChecked) {
  Toast.makeText(MainActivity.this, button.getText(), 1).show();
  }
  break;
 default:
  break;
 }
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
 }
}

(3)顯示結(jié)果,當(dāng)點(diǎn)擊的時(shí)候顯示文字

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

  • Android RxJava異步數(shù)據(jù)處理庫(kù)使用詳解

    Android RxJava異步數(shù)據(jù)處理庫(kù)使用詳解

    RxJava是一種異步數(shù)據(jù)處理庫(kù),也是一種擴(kuò)展的觀察者模式。對(duì)于Android開發(fā)者來(lái)說,使用RxJava時(shí)也會(huì)搭配RxAndroid,它是RxJava針對(duì)Android平臺(tái)的一個(gè)擴(kuò)展,用于Android 開發(fā),它提供了響應(yīng)式擴(kuò)展組件,使用RxAndroid的調(diào)度器可以解決Android多線程問題
    2022-11-11
  • Android?gradient?使用小結(jié)

    Android?gradient?使用小結(jié)

    在Android中使用gradient(漸變)通常是通過drawable文件來(lái)設(shè)置背景,下面是可以直接用的幾種用法匯總,包括線性漸變、徑向漸變、掃描漸變(sweep)等,感興趣的朋友一起看看吧
    2025-04-04
  • Android開發(fā)技巧之ViewStub控件惰性裝載

    Android開發(fā)技巧之ViewStub控件惰性裝載

    布局文件中的控件并不一定在程序啟動(dòng)時(shí)全都用到,有一些控件只在特定的情況下才會(huì)被使用到;我們急需一種機(jī)制來(lái)改變<include>標(biāo)簽的這種行為,只在需要時(shí)裝載控件。這種機(jī)制就是本節(jié)要介紹的ViewStub控件
    2013-01-01
  • Android?Compose狀態(tài)改變動(dòng)畫animateXxxAsState使用詳解

    Android?Compose狀態(tài)改變動(dòng)畫animateXxxAsState使用詳解

    這篇文章主要為大家介紹了Android?Compose狀態(tài)改變動(dòng)畫animateXxxAsState使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • Android實(shí)現(xiàn)搖一搖簡(jiǎn)單功能

    Android實(shí)現(xiàn)搖一搖簡(jiǎn)單功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)搖一搖簡(jiǎn)單功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-03-03
  • Android指紋解鎖方法解析

    Android指紋解鎖方法解析

    這篇文章主要為大家詳細(xì)解析了Android指紋解鎖方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android MVP模式面向接口寫法

    Android MVP模式面向接口寫法

    這篇文章主要介紹了Android MVP模式面向接口寫法,MVP模式也出來(lái)好幾年了,很成熟所以也導(dǎo)致寫法有很多種,google提供了多種mvp模式,但我今天只講解最簡(jiǎn)單的面向接口,需要詳細(xì)了解可以參考下文
    2023-05-05
  • android開發(fā)實(shí)踐之ndk編譯命令簡(jiǎn)單示例

    android開發(fā)實(shí)踐之ndk編譯命令簡(jiǎn)單示例

    這篇文章主要給大家介紹了在android中ndk編譯命令使用的相關(guān)資料,文中詳細(xì)介紹了ndk-build命令行參數(shù),并通過簡(jiǎn)單的示例代碼給大家介紹了如何編寫 .c 文件,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-06-06
  • Android自定義控件如何在XML文件中使用自定義屬性

    Android自定義控件如何在XML文件中使用自定義屬性

    這篇文章主要為大家介紹了Android自定義控件之如何在XML文件中使用自定義屬性示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • Android SurfaceView與TextureView使用方法詳細(xì)講解

    Android SurfaceView與TextureView使用方法詳細(xì)講解

    SurfaceView和TextureView都繼承View,與普通的View不同的是,它倆可以在獨(dú)立線程中繪制渲染,性能更高,所以常被應(yīng)用在對(duì)繪制速率要求比較高的場(chǎng)景,比如相機(jī)預(yù)覽,視頻播放等等
    2022-10-10

最新評(píng)論

阳新县| 金乡县| 津南区| 炉霍县| 宜黄县| 新建县| 莱州市| 通辽市| 临泽县| 巴彦淖尔市| 长沙县| 建始县| 绥芬河市| 大名县| 嘉义县| 宿州市| 云霄县| 弋阳县| 探索| 城市| 平昌县| 牡丹江市| 澳门| 兰溪市| 大埔县| 武川县| 灵寿县| 普洱| 吐鲁番市| 巩留县| 大足县| 桂林市| 凤阳县| 新平| 资中县| 丰镇市| 桂阳县| 朝阳市| 手游| 巫溪县| 亚东县|