• 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;

    }

    }

     

     

    }

     

  • 相关阅读:
    hdu 5171(矩阵快速幂,递推)
    hdu 1316(大整数)
    hdu 5170(数学)
    hdu 5167(dfs)
    hdu 5166(水题)
    hdu 5720(贪心+区间合并)
    BestCoder 2nd Anniversary的前两题
    hdu 3065(AC自动机)
    2.3绘制构造线与射线
    查找ARP攻击源
  • 原文地址:https://www.cnblogs.com/cn-chy-com/p/7931752.html
Copyright © 2020-2023  润新知