你好,游客 登录 注册 搜索
背景:
阅读新闻

Andriod游戏开发系统控件-RadioButton

[日期:2012-05-13] 来源:Linux社区  作者:wwj [字体:大 中 小]

修改velue文件

=>>string.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.   
  4.     <string name="hello">Hello World, RadioButtonActivity!</string>  
  5.     <string name="app_name">RadioButton</string>  
  6.     <string name="radB1">RadioButton1</string>  
  7.     <string name="radB2">RadioButton2</string>  
  8.     <string name="radB3">RadioButton3</string>  
  9.   
  10. </resources>  

修改Activity文件

=>>RadioButtonProject.java

  1. package com.radioButton;  
  2.   
  3. import Android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.widget.RadioButton;  
  6. import android.widget.RadioGroup;  
  7. import android.widget.RadioGroup.OnCheckedChangeListener;  
  8. import android.widget.Toast;  
  9.   
  10. public class RadioButtonActivity extends Activity implements OnCheckedChangeListener{  
  11.     private RadioButton rb1,rb2,rb3;  
  12.     private RadioGroup rg;  
  13.     /** Called when the activity is first created. */  
  14.     @Override  
  15.     public void onCreate(Bundle savedInstanceState) {  
  16.         super.onCreate(savedInstanceState);  
  17.         setContentView(R.layout.main);  
  18.         rb1 = (RadioButton) findViewById(R.id.rb1);  
  19.         rb2 = (RadioButton) findViewById(R.id.rb2);  
  20.         rb3 = (RadioButton) findViewById(R.id.rb3);  
  21.         rg = (RadioGroup) findViewById(R.id.radGrp);  
  22.         rg.setOnCheckedChangeListener(this);//将单选组绑定监听器   
  23.     }  
  24.     //重写监听器函数   
  25.     public void onCheckedChanged(RadioGroup group, int checkedId) {  
  26.         if(group==rg){  
  27.             String rbName = null;  
  28.             if(checkedId == rb1.getId()){  
  29.                 rbName = rb1.getText().toString();  
  30.             } else if (checkedId == rb2.getId()){  
  31.                 rbName = rb2.getText().toString();  
  32.             } else if(checkedId == rb3.getId()){  
  33.                 rbName = rb3.getText().toString();  
  34.             }  
  35.             Toast.makeText(this,"选择了下标为“"+ rbName + "”的单选按钮",  
  36.                     Toast.LENGTH_LONG).show();  
  37.               
  38.         }  
  39.           
  40.     }     
  41. }  

更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11

linux
相关资讯       Andriod游戏开发  Andriod编程入门 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* bnygzj 发表于 2012/8/9 13:53:42
怎么没有代码啊