//activity_main.xml
<LinearLayout 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" tools:context="com.vincentlin.radiogroup.MainActivity" > <RadioGroup android:id="@+id/radioGroup1" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radio0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="@string/male" /> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/female" /> </RadioGroup> </LinearLayout>
//strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">RadioGroup</string> <string name="hello_world">Hello world!</string> <string name="action_settings">Settings</string> <string name="male">男</string> <string name="female">女</string> </resources>
//MainActivity.java
package com.vincentlin.radiogroup; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; public class MainActivity extends Activity 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); //實(shí)現(xiàn)RadionGroup的事件監(jiān)聽 rg.setOnCheckedChangeListener( this); } @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radio0: Log.i("tag","當(dāng)前為男性"); break; case R.id.radio1: Log.i("tag","當(dāng)前為女性"); break; default: break; } } }
分享標(biāo)題:android基礎(chǔ)四之RadioGroup
當(dāng)前URL:http://jinyejixie.com/article30/pphopo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、服務(wù)器托管、網(wǎng)站建設(shè)、App設(shè)計(jì)、標(biāo)簽優(yōu)化、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)