MainActivity中代码

package com.mz.dx;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.RadioGroup.OnCheckedChangeListener;import android.widget.Toast;public class MainActivity extends Activity {    private RadioGroup sex_radioGroup;    private Button btn_s;    /** Called when the activity is first created. */    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        sex_radioGroup=(RadioGroup)findViewById(R.id.sex_ridioGroup);        sex_radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {            public void onCheckedChanged(RadioGroup arg0, int arg1) {                // TODO Auto-generated method stub                if(arg1==R.id.sex_man){                    Toast toast=Toast.makeText(MainActivity.this, "您选中的是男", Toast.LENGTH_LONG);                    toast.show();                }else{                    Toast toast=Toast.makeText(MainActivity.this, "您选中的是女", Toast.LENGTH_LONG);                    toast.show();                }            }        });        btn_s=(Button)findViewById(R.id.btn_s);        btn_s.setOnClickListener(new OnClickListener() {            public void onClick(View v) {                // TODO Auto-generated method stub                for(int i=0;iif(radio.isChecked()){                        Toast toast=Toast.makeText(MainActivity.this,"您选中的是:"+radio.getText(),Toast.LENGTH_SHORT);                        toast.show();                    }                }            }        });    }}

前端代码

<?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="选择性别"/>   <RadioGroup        android:id="@+id/sex_ridioGroup"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:orientation="horizontal">       <RadioButton            android:id="@+id/sex_man"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:text="男"/>       <RadioButton            android:id="@+id/sex_woman"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:text="女"/>   RadioGroup>   <Button        android:id="@+id/btn_s"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:text="提交"/>LinearLayout>

解析未完。。。

更多相关文章

  1. android radiobutton选中字体颜色改变的方法
  2. android点击空白区域隐藏软键盘的实现
  3. Android中获取系统的时间
  4. Android(安卓)drawText 纵向居中
  5. 【Android】viewpager banner 广告 自动轮播 小圆点
  6. android 打开新浪微博代码
  7. Android(安卓)系统是否要重启时弹出框
  8. Android中两个控件滑动效果冲突的解决办法
  9. Android(安卓)获取电池基本信息代码

随机推荐

  1. Android系统添加自己写的工具
  2. Java - android中的枚举类型(Enum)
  3. 你还在问android横竖屏切换的生命周期?
  4. Android——android studio 安装完成之后
  5. Android启动过程深入解析
  6. ok6410开发板android底层驱动模块编写,出
  7. TextView属性大全+单行显示长文本
  8. Android(安卓)NDK开发基础-------环境搭
  9. Settings: android 组件如何响应语言变化
  10. Android中的Intent[转]