zoukankan      html  css  js  c++  java
  • Android UI开发之RadioButton

    package com.android.liu.ui;

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

    import com.android.liu.R;

    public class RadioActivity extends Activity {
     RadioGroup m_RadioGroup;
     RadioButton m_radio1,m_radio2,m_radio3,m_radio4;
     @Override
     public void onCreate(Bundle inSaveState)
     {
      super.onCreate(inSaveState);
      setContentView(R.layout.radio);
      
      m_RadioGroup=(RadioGroup) this.findViewById(R.id.RadioGroup);
      m_radio1=(RadioButton) this.findViewById(R.id.RadioButton1);
      m_radio2=(RadioButton) this.findViewById(R.id.RadioButton2);
      m_radio3=(RadioButton) this.findViewById(R.id.RadioButton3);
      m_radio4=(RadioButton) this.findViewById(R.id.RadioButton4);
      
      m_RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
       
       @Override
       public void onCheckedChanged(RadioGroup group, int checkedId) {
        if(checkedId==m_radio2.getId())
        {
         display("正确答案:"+m_radio2.getText()+",恭喜你回答正确");
        }else{
         display("选择的是错误答案");
        }
        
       }
      });
      
     }
     
     public void display(String msg)
     {
      Toast.makeText(RadioActivity.this, msg, Toast.LENGTH_SHORT).show();
     }
    }

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
       
        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="请选择正确答案" 
       
        ></TextView>
       
        <RadioGroup
        android:id="@+id/RadioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_x="3px"
        android:layout_y="54px"
           >
           <RadioButton
            android:id="@+id/RadioButton1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/RadioButton1"
           />
          
            <RadioButton
            android:id="@+id/RadioButton2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/RadioButton2"
           />
          
            <RadioButton
            android:id="@+id/RadioButton3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/RadioButton3"
           />
          
            <RadioButton
            android:id="@+id/RadioButton4"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/RadioButton4"
           />
           </RadioGroup>
          
           <RatingBar
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:numStars="3"
           android:id="@+id/ratingBar"
          
          
           ></RatingBar>
          
          
          
    </LinearLayout>

  • 相关阅读:
    在Leangoo里怎么添加,移动列表,修改列表名称?
    在Leangoo里怎么列表示例,插入列表?
    tomcat如何按站点调试本机程序
    ORA-12519, TNS:no appropriate service handler found
    mysql 远程访问
    手机端调试成功笔记
    Cannot find class for bean with name service
    android模拟器不能用键盘
    eclipse使用基础--让toolbar显示自己想要的内容
    mysql解压版安装
  • 原文地址:https://www.cnblogs.com/liuzenglong/p/2172031.html
Copyright © 2011-2022 走看看