当前位置 : 主页 > 编程语言 > c++ >

RadioGroup的简单应用

来源:互联网 收集:自由互联 发布时间:2021-06-30
layout.xml MainActivity.java package com.test.radiogroup;import android.os.Bundle;import android.support.annotation.IdRes;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.widget.RadioGroup;public class
layout.xml
 

 

    
   
    
    
  

 
MainActivity.java
package com.test.radiogroup;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity {
    private RadioGroup rg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);
        rg = (RadioGroup) findViewById(R.id.radioGroup1);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                switch (checkedId){
                    case R.id.radioButton3:
                        Log.i("tag","你选择了男");
                    break;
                    case R.id.radioButton4:
                        Log.i("tag","你选择了女");
                    break;
                    default:
                        break;
                }
            }
        });
    }
}
上一篇:TableLayout的简单应用
下一篇:MinaHttpServer
网友评论