Android 单选框RadioGrop的使用。里面添加的是RadioButton

package com.radiodemo;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;public class MainActivity extends Activity {/************************************* * 单选框RadioButton的使用 *  * 1.定义见布局文件 2.事件的添加方法 *  ***********************************/private TextView textView;private RadioGroup radioGroup;private RadioButton radioButton1, radioButton2;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);// 关联布局中的控件textView = (TextView) findViewById(R.id.textView);// 用来显示选择radioGroup = (RadioGroup) findViewById(R.id.radioGroup);radioButton1 = (RadioButton) findViewById(R.id.radioButton1);radioButton2 = (RadioButton) findViewById(R.id.radioButton2);radioGroup.setOnCheckedChangeListener(mChangeListener);}// 响应事件的函数。private RadioGroup.OnCheckedChangeListener mChangeListener = new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubif (radioButton1.getId() == checkedId) {textView.setText(radioButton1.getText());} else {textView.setText(radioButton2.getText());}}};@Overridepublic 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;}}


布局文件main.xml

                                            


 

 

 

 

更多相关文章

  1. Android触控事件
  2. [转]android layout布局属性
  3. Android Layout 布局属性全解
  4. AndroiManifest.xml文件中android属性
  5. 常见UI布局
  6. Android 将从网络获取的数据缓存到私有文件

随机推荐

  1. 具有线程/回复的私人消息系统
  2. PHP:在类中使用数据库
  3. laravel 框架自带表单验证
  4. php static静态变量及方法详解
  5. 为什么要使用PHP框架?
  6. 通过添加3hrs从服务器中重新获取CURTIME()
  7. laravel 4路由::控制器()方法返回NotFoun
  8. 使用.php文件生成一个MySQL转储文件。
  9. 使用mod_rewrite将文件夹转换为查询字符
  10. PHP的钩子实现解析