android基础四之RadioGroup
//activity_main.xml
//strings.xml
RadioGroup Hello world! Settings 男 女
//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); //实现RadionGroup的事件监听 rg.setOnCheckedChangeListener( this); } @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radio0: Log.i("tag","当前为男性"); break; case R.id.radio1: Log.i("tag","当前为女性"); break; default: break; } } }
文章名称:android基础四之RadioGroup
本文路径:http://myzitong.com/article/pphopo.html