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

Android開發(fā)之RadioGroup的簡單使用與監(jiān)聽示例

 更新時間:2017年07月28日 11:58:57   作者:LoveJulin  
這篇文章主要介紹了Android開發(fā)之RadioGroup的簡單使用與監(jiān)聽,結(jié)合實例形式分析了Android針對RadioGroup單選按鈕簡單實用技巧,需要的朋友可以參考下

本文實例講述了Android RadioGroup的簡單使用與監(jiān)聽。分享給大家供大家參考,具體如下:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" >
  <RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <RadioButton
      android:id="@+id/radio0"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:checked="true"
      android:text="男" />
    <RadioButton
      android:id="@+id/radio1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="女" />
  </RadioGroup>
</LinearLayout>

MainActivity.java

package com.example.hello;
import android.support.v7.app.ActionBarActivity;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity implements OnCheckedChangeListener{
  private RadioGroup rg;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    rg = (RadioGroup) findViewById(R.id.radioGroup1);
    rg.setOnCheckedChangeListener(this);
  }
  @Override
  public void onCheckedChanged(RadioGroup group, int checkedId) {
    switch(checkedId){
      case R.id.radio0:
        Toast.makeText(MainActivity.this, "男", 1).show();
        break;
      case R.id.radio1:
        Toast.makeText(MainActivity.this, "女", 1).show();
        break;
    }
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

最新評論

临泽县| 浏阳市| 池州市| 革吉县| SHOW| 黎川县| 宜川县| 兴国县| 巴中市| 陇西县| 长武县| 新宾| 库伦旗| 库尔勒市| 喜德县| 华安县| 克山县| 蒙城县| 汉源县| 玉门市| 闽侯县| 侯马市| 丰城市| 阳高县| 达拉特旗| 武邑县| 筠连县| 达尔| 抚州市| 常德市| 华坪县| 丽水市| 莱阳市| 通许县| 宣恩县| 博野县| 新昌县| 铁岭市| 南澳县| 邛崃市| 玉林市|