注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

2011终点

2011终点

 
 
 

日志

 
 

RadioGroup RadioButton CheckBox  

2012-01-27 00:47:30|  分类: Android学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

1.这是一个LayoutActivity 的类

package cn.wzg.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;


public class LayoutActivity extends Activity {
 private RadioGroup radiogroup = null;
 private RadioButton radiobutton1 = null;
 private RadioButton radiobutton2 = null;
 private CheckBox swingbox = null;
 private CheckBox runbox = null;
 private CheckBox bookbox = null;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  radiogroup = (RadioGroup) findViewById(R.id.radioGroup1);
  radiobutton1 = (RadioButton) findViewById(R.id.radio0);
  radiobutton2 = (RadioButton) findViewById(R.id.radio1);
  swingbox = (CheckBox) findViewById(R.id.checkBox1);
  runbox = (CheckBox) findViewById(R.id.checkBox2);
  bookbox = (CheckBox) findViewById(R.id.checkBox3);
  radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

   @Override
   public void onCheckedChanged(RadioGroup group, int checkedId) {
    // TODO Auto-generated method stub
    if (radiobutton1.getId() == checkedId) {
     System.out.print("男");
     Toast.makeText(LayoutActivity.this, "男",Toast.LENGTH_SHORT );
     
    } else if (radiobutton2.getId() == checkedId) {
     System.out.print(" 女");
     Toast.makeText(LayoutActivity.this, "女",Toast.LENGTH_SHORT );
    }

   }
  });
  
  swingbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
   
   @Override
   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // TODO Auto-generated method stub
    if(isChecked){
     System.out.print("游泳");
    }else{
     System.out.print("没有选择游泳");
    }
    
   }
  });
  
  runbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
   
   @Override
   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // TODO Auto-generated method stub
    if(isChecked){
     System.out.print("跑步");
    }else{
     System.out.print("没有选择跑步");
    }
    
   }
  });
  
  bookbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
   
   @Override
   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // TODO Auto-generated method stub
    if(isChecked){
     System.out.print("读书");
    }else{
     System.out.print("没有选择读书");
    }
    
   }
  });
 }
}

 

 

2.main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        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/man" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/woman" />
    </RadioGroup>

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/run" />


    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/swing" />

    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/book" />
   
</LinearLayout>

 

3.String.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">介绍</string>
    <string name="app_name">Layout_07</string>
    <string name="man">男</string>
    <string name="woman">女</string>
    <string name="run">跑步</string>
    <string name="swing">游泳</string>
    <string name="book">看书</string>

</resources>


结果:
RadioGroup  RadioButton CheckBox - lvjian118 - 2011终点
  评论这张
 
阅读(366)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018