android基础四之RadioGroup-创新互联

//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);
  //实现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;
  }
  
 }
 
}

成都创新互联公司拥有10余年成都网站建设工作经验,为各大企业提供做网站、成都网站建设服务,对于网页设计、PC网站建设(电脑版网站建设)、成都APP应用开发、wap网站建设(手机版网站建设)、程序开发、网站优化(SEO优化)、微网站、国际域名空间等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了很多网站制作、网站设计、网络营销经验,集策划、开发、设计、营销、管理等网站化运作于一体,具备承接各种规模类型的网站建设项目的能力。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

网页名称:android基础四之RadioGroup-创新互联
转载来源:https://www.cdcxhl.com/article18/djpjgp.html

成都网站建设公司_创新互联,为您提供品牌网站设计服务器托管Google网站改版企业网站制作标签优化

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司