zoukankan      html  css  js  c++  java
  • 事件(2)

    单选发生变化

    OnCheckedChangeListener
      rg=(RadioGroup) findViewById(R.id.rge1);
      rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
          RadioButton rb=(RadioButton) findViewById(checkedId);
          String str=rb.getText().toString();
          tv.setText(str);
        }
      });

     1 public class Click extends Activity{
     2     private Button bt;            //定义按钮
     3     private TextView tv;        //定义信息显示组件
     4     private EditText et;        //定义文本输入组件
     5     
     6     protected void onCreate(Bundle savedInstanceState) {
     7         super.onCreate(savedInstanceState);
     8         setContentView(R.layout.event);
     9         et=(EditText)findViewById(R.id.ete1);            //取得文本编辑组件
    10         bt=(Button)findViewById(R.id.bte1);                //取得按钮
    11         tv=(TextView)findViewById(R.id.tve1);            //取得文本显示
    12         
    13         rg=(RadioGroup) findViewById(R.id.rge1);
    14         rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    15             
    16             @Override
    17             public void onCheckedChanged(RadioGroup group, int checkedId) {
    18                 RadioButton rb=(RadioButton) findViewById(checkedId);
    19                 String str=rb.getText().toString();
    20                 tv.setText(str);
    21             }
    22         });
    23 }
    代码示例
     1 <RadioGroup
     2           android:id="@+id/rge1"
     3         android:layout_width="fill_parent" 
     4         android:layout_height="wrap_content" 
     5       />
     6       
     7       <RadioButton
     8           android:id="@+id/rbe1"
     9         android:layout_width="fill_parent" 
    10         android:layout_height="wrap_content" 
    11           android:text="香蕉"
    12       >
    13       <RadioButton
    14           android:id="@+id/rbe2"
    15         android:layout_width="fill_parent" 
    16         android:layout_height="wrap_content" 
    17           android:text="苹果"
    18       />
    19       </RadioButton>
    20        
    21       <TextView
    22           android:id="@+id/tve1"
    23         android:layout_width="fill_parent" 
    24         android:layout_height="wrap_content" 
    25            android:background="#FF0000"
    26       />
    xml文件
  • 相关阅读:
    Flappy Bird c++试验版
    log4net在windows 2003 iis6下使用的注意事项
    IIS6下, web.config配置为targetFramework="4.0"时出404错误
    mercurial(hg)使用
    Firebird数据库相关备忘录
    关于项目开发进度的看法
    日常数据分析的主要内容仍是结构化计算
    集算器协助java处理多样性数据源之HDFS
    集算器协助Java处理多样性数据源之Hive
    集算器协助java处理多样性数据源之JSON
  • 原文地址:https://www.cnblogs.com/yang82/p/6957829.html
Copyright © 2011-2022 走看看