重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
//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; } } }