山寨开机选择四大系统-----------RadioGroup 、RadioButton单选按钮


以下是java 文件

public class Activity01 extends Activity {
	/**
	 * 创建TextView对象
	 * 创建RadioGroup对象
	 * 创建4个RadioButton对象
	 */
	TextView m_T;
    RadioGroup m_RG;
    RadioButton m_R1, m_R2, m_R3, m_R4; 
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        /**
		 * 获得TextView对象
		 * 获得RadioGroup对象
		 * 获得4个RadioButton对象
		 */
        m_T = (TextView)findViewById(R.id.TextView01);
        m_RG =(RadioGroup)findViewById(R.id.RadioGroup01);
        m_R1=(RadioButton)findViewById(R.id.RadioButton01);
        m_R2 =(RadioButton)findViewById(R.id.RadioButton02);
        m_R3 =(RadioButton)findViewById(R.id.RadioButton03);
        m_R4 =(RadioButton)findViewById(R.id.RadioButton04);
        
       /* 设置事件监听  */
       m_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
    	   public void onCheckedChanged(RadioGroup group, int checkedId){
    		   if(checkedId == m_R2.getId()){
    			   DisplayToast("恭喜你" + m_R2.getText()+ ",进入iphone4系统中~~~~");
    		   }else{
    			   DisplayToast("系统错误,该系统已损坏!");
    		   }
    	   }
    	   
       });
        
    }
    
    public void DisplayToast(String str){
    	Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG);
    	//设置toast显示的位置  Gravity 重力
    	toast.setGravity(Gravity.TOP, 0, 220);
    	//显示该Toast
    	toast.show();
    }
    
}


以下是UI的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:id = "@+id/TextView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"  
         />
    <!-- 单选组框 -->            <!-- 选项按钮RadioButton -->
    <RadioGroup
        android:id = "@+id/RadioGroup01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/RadioGroup01"  
         >    

    	<RadioButton
    	    android:id="@+id/RadioButton01"
    	    android:layout_width="fill_parent"
    	    android:layout_height="fill_parent"
    	    android:text="@string/RadioButton01" />

    	<RadioButton
	        android:id = "@+id/RadioButton02"
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:text="@string/RadioButton02"  
         />
    	<RadioButton
	        android:id = "@+id/RadioButton03"
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:text="@string/RadioButton03"  
         />
    	<RadioButton
	        android:id = "@+id/RadioButton04"
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:text="@string/RadioButton04"  
         />
	
        
     </RadioGroup>   
</LinearLayout>


以下是string .xml里面的

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

   
    <string name="hello">选择进入系统</string>
    <string name="app_name">系统选择</string>
    <string name="RadioGroup01">RadioGroup01</string>
    <string name="RadioButton01">android2.3.3</string>
    <string name="RadioButton02">iphone4</string>
    <string name="RadioButton03">windowPhone8</string>
    <string name="RadioButton04">塞班系统</string>
    

</resources>



运行图片后为:


选择iPhone4 则显示 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值