国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

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

2019-10-22 18:31:27
字體:
來源:轉載
供稿:網友

本文實例講述了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;    }  }}

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


注:相關教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 奉化市| 罗定市| 吴桥县| 盐亭县| 乳山市| 定州市| 溆浦县| 新余市| 拉萨市| 莫力| 鄂州市| 喀什市| 抚顺市| 青岛市| 淮北市| 岱山县| 舒兰市| 长治县| 彭水| 开江县| 福清市| 桦南县| 虹口区| 灵山县| 息烽县| 湘西| 平原县| 两当县| 阜新| 酒泉市| 来凤县| 新蔡县| 城固县| 疏附县| 河北区| 奎屯市| 扶余县| 崇明县| 老河口市| 乾安县| 崇义县|