RadioGroup组与onCheckedChanged事件
来源:互联网 发布:运动控制器编程语言 编辑:程序博客网 时间:2024/06/06 09:44
//MainActivity.java
package com.example.test;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView tv;
private RadioGroup rg;
private RadioButton rb1;
private RadioButton rb2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.tv1);
rg=(RadioGroup)findViewById(R.id.rg);
rb1=(RadioButton)findViewById(R.id.rb1);
rb2=(RadioButton)findViewById(R.id.rb2);
rg.setOnCheckedChangeListener(mChangeRadio);
}
private RadioGroup.OnCheckedChangeListener mChangeRadio = new
RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
// TODO Auto-generated method stub
if(checkedId==rb1.getId())
tv.setText(rb1.getText());
else if(checkedId==rb2.getId())
tv.setText(rb2.getText());
}
};
}
//activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="24dp"
android:layout_marginTop="32dp"
android:text="who are you?" />
<RadioGroup
android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv1"
android:layout_below="@+id/tv1"
android:layout_marginTop="20dp" >
<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="boy" />
<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/rb1"
android:layout_below="@+id/rb1"
android:text="gril" />
</RadioGroup>
</RelativeLayout>
- RadioGroup组与onCheckedChanged事件
- RadioGroup组与onCheckedChanged事件
- Android中RadioGroup组与onCheckedChanged事件
- Android入门--RadioGroup 组与onCheckedChanged 事件
- 4.6 向左或向右RadioGroup组与onCheckedChanged事件
- 4.6向左或向右 ---RadioGroup组与onCheckedChanged事件
- 向左向右(RadioGroup组与onCheckedChanged)
- RadioGroup与onCheckedChanged事件,实时显示所选
- RadioGroup调用check()方法onCheckedChanged()调用多次
- 执行RadioGroup的check(Id)方法,会触发onCheckedChanged多次
- 有关RadioGroup的OnCheckedChanged方法执行多次的探讨
- GridView中的CheckBox单击事件(oncheckedchanged)
- CheckBox的使用(一):onCheckedChanged事件
- GridView中的CheckBox单击事件(oncheckedchanged)
- RadioGroup 监听事件
- RadioGroup的点击事件
- RadioGroup调用check(id)方法时,onCheckedChanged方法被执行多次解决办法
- RadioGroup调用check(int)方法时,onCheckedChanged方法被执行两次
- NYOJ 71 独木舟上的旅行 贪心算法 之 乘船问题
- 【研究总结】2-sat问题
- 札记--名词解释
- Java连接MYSQL 数据库的连接步骤
- xargs命令
- RadioGroup组与onCheckedChanged事件
- 关于Unicode 和 UTF-8 的思考
- 从B树中删除关键字
- C#对象诞生记之构造函数都干了啥
- PowerDesigner连接MySQL,建立逆向工程图解
- 最短路—1008
- 基于WCF 的远程数据库服务访问技术
- VS2010中的调试技巧
- <welcome-file-list>404