• android的radiobutton和radiogroup


    1.radiogroup

      1.1radiobutton的集合,表示一类radiobutton,提供多选一机制,譬如大家常用的选择男女的选项。

      1.2radiogroup的属性:

                android:orientation=“vertica”(垂直排列)/“horizontal”(水平排列)

    2.实例代码

    layout:

    <RelativeLayout 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=".MainActivity" >
    
        <RadioGroup
            android:id="@+id/radioGroup1"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="23dp" >
    
            <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="女" />
    
    
        </RadioGroup>
    
    </RelativeLayout>

    .java

    package com.example.radiobutton;
    
    import android.os.Bundle;
    import android.util.Log;
    import android.app.Activity;
    import android.view.Menu;
    import android.widget.RadioGroup;
    import android.widget.RadioGroup.OnCheckedChangeListener;
    
    public class MainActivity extends Activity implements OnCheckedChangeListener {
        private 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 boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public void onCheckedChanged(RadioGroup arg0, int arg1) {
            // TODO Auto-generated method stub
            switch (arg1) {
            case R.id.radio0:
                Log.i("tag", "你是一个男生");
                
                break;
            case R.id.radio1:
                Log.i("tag", "你是一个女生");
                break;
            default:
                break;
            }
        }
    
    }
    本博客基于网络课程完成,旨在学习,有错误请指正!
  • 相关阅读:
    keras: 在构建LSTM模型时,使用变长序列的方法
    keras:Exception: Error when checking model target
    Scipy.sparse矩阵的存储,读取和转化为稠密矩阵
    Feature Selection 其一 —— Filter Approach
    超限学习机 (Extreme Learning Machine, ELM) 学习笔记 (一)
    [IR课程笔记]Web search
    [数据挖掘课程笔记]无监督学习——聚类(clustering)
    [IR课程笔记]Query Refinement and Relevance Feedback
    [IR课程笔记]Hyperlink-Induced Topic Search(HITS)
    DIARY10-05
  • 原文地址:https://www.cnblogs.com/comefuture/p/6733475.html
Copyright © 2020-2023  润新知