zoukankan      html  css  js  c++  java
  • 单选与复选

    activity_ui1.xml

    <?xml version="1.0" encoding="utf-8"?>
    <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:padding="10dp"
        android:orientation="vertical"
        tools:context="com.hanqi.application3.UIActivity1"
        android:weightSum="1">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="请选择Android的开发语言是什么"/>
        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/rb"
            >
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="C++"
                android:id="@+id/rb1"
                android:layout_marginRight="30dp"
                android:checked="true"
                />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="C"
                android:id="@+id/rb2"
                android:layout_marginRight="30dp"
                />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="JAVA"
                android:id="@+id/rb3"
                android:layout_marginRight="30dp"
                />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="C#"
                android:id="@+id/rb4"
                android:layout_marginRight="30dp"
                />
    
        </RadioGroup>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="请选择字体效果"/>
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="宋体"
            android:id="@+id/cb_st"
            android:checked="true"
            />
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="加粗"
            android:id="@+id/cb_jc"
            />
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="斜体"
            android:id="@+id/cb_xt"
            />
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="下划线"
            android:id="@+id/cb_xhx"
            />
    
    
    </LinearLayout>

    UIActivity1.java

    package com.hanqi.application3;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.support.annotation.IdRes;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.RadioButton;
    import android.widget.RadioGroup;
    import android.widget.Toast;
    
    import static android.widget.CompoundButton.*;
    
    public class UIActivity1 extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_ui1);
    
            RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rb);
    
            radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    
                public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
    
                    if (checkedId == R.id.rb3) {
                        Toast.makeText(UIActivity1.this, "选对了", Toast.LENGTH_SHORT).show();
                    }
                    RadioButton rb = (RadioButton) findViewById(checkedId);
    
                    Toast.makeText(UIActivity1.this, rb.getText(), Toast.LENGTH_SHORT).show();
                }
    
    
            });
    
            CheckBox cb_st= (CheckBox)findViewById(R.id.cb_st);
            cb_st.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
            CheckBox cb_xt= (CheckBox)findViewById(R.id.cb_xt);
            cb_xt.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
            CheckBox cb_jc= (CheckBox)findViewById(R.id.cb_jc);
            cb_jc.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
            CheckBox cb_xhx= (CheckBox)findViewById(R.id.cb_xhx);
            cb_xhx.setOnCheckedChangeListener(new CBOnCheckChangeListenter());
        }
    
    
    
        private class CBOnCheckChangeListenter implements OnCheckedChangeListener
        {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    
                CheckBox cb = (CheckBox)buttonView;
                if (isChecked) {
                    Toast.makeText(UIActivity1.this, "选中了", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Toast.makeText(UIActivity1.this, "取消了", Toast.LENGTH_SHORT).show();
                }
            }
        }
    }
  • 相关阅读:
    DHTML【3】--HTML
    PS图层混合算法之六(差值,溶解, 排除)
    PS图层混合算法之五(饱和度,色相,颜色,亮度)
    curl+个人证书(又叫客户端证书)访问https站点
    密钥库文件格式[keystore]代码
    PS图层混合算法之四(亮光, 点光, 线性光, 实色混合)
    libcurl使用认证证书 https认证
    openssl指定证书密码建立连接
    PS图层混合算法之三(滤色, 叠加, 柔光, 强光)
    openssl编译出错解决
  • 原文地址:https://www.cnblogs.com/WY404683569/p/5331663.html
Copyright © 2011-2022 走看看