zoukankan      html  css  js  c++  java
  • RadioGroup和RadioButton

     

     

     

     

    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"

        android:paddingBottom="@dimen/activity_vertical_margin"

        android:paddingLeft="@dimen/activity_horizontal_margin"

        android:paddingRight="@dimen/activity_horizontal_margin"

        android:paddingTop="@dimen/activity_vertical_margin"

        tools:context="com.example.radiobuttondemo.MainActivity" >

     

        <RadioGroup

            android:id="@+id/radioGroup1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content" 

            android:orientation="horizontal">

     

            <RadioButton

                android:id="@+id/radio0"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:checked="true"

                android:text="游泳" />

     

            <RadioButton

                android:id="@+id/radio1"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="球类" />

     

            <RadioButton

                android:id="@+id/radio2"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="编程" />

        </RadioGroup>

     

    </LinearLayout>

    MainActivity.java

    package com.example.radiobuttondemo;

     

    import android.os.Bundle;

    import android.support.v7.app.ActionBarActivity;

    import android.util.Log;

    import android.widget.CompoundButton;

    import android.widget.RadioGroup;

    import android.widget.RadioGroup.OnCheckedChangeListener;

     

    public class MainActivity extends ActionBarActivity implements OnCheckedChangeListener{

    RadioGroup rg;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    rg=(RadioGroup) findViewById(R.id.radioGroup1);

    rg.setOnCheckedChangeListener(this);

    }

    @Override

    public void onCheckedChanged(RadioGroup group, int checkedId) {

    switch(checkedId){

    case R.id.radio0:

    Log.i("msg","游泳");

    break;

    case R.id.radio1:

    Log.i("msg","球类");

    break;

    case R.id.radio2:

    Log.i("msg","编程");

    break;

    }

    }

     

     

    }

     

  • 相关阅读:
    Google Map API Version3 :代码添加和删除marker标记
    ArcGIS Server开发教程系列(8)ArcGIS API for Javascript-控件(小部件)
    ArcGIS Server开发教程系列(8)ArcGIS API for Javascript-控件(小部件)(续)纯代码
    ArcGIS Server开发教程系列(7)使用ArcGIS API for Javascript-Hello World
    ArcGIS Server开发教程系列(3)切片
    3.1、常用图片格式
    【Emmet】HTML速写之Emmet语法规则
    2.11、特征布局实例讲习
    2.10、background属性
    2.9、定位
  • 原文地址:https://www.cnblogs.com/cn-chy-com/p/7931752.html
Copyright © 2011-2022 走看看