安卓编程小菜鸟之RadioButton 安卓radiobutton 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个比较容易实现哦。比如在第一组a,b的radiodgroup.setOnchekeChangeLister(),里面判断if(checkId == mRadioButtonA.getId()){mRadioButtonC.setChecked(true)} 你这个是不是单选框?CheckBox才是多选吧。 我也这么写了,但是运行起来,就会有异常class RadioGroupLisener implements OnCheckedChangeListener{ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(checkedId==maleButton.getId()) { System.out.println("选中male"); CButton.setChecked(true); } else if (checkedId==famaleButton.getId()) { System.out.println("选中famale"); } } } <LinearLayout 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" android:orientation="vertical" tools:context=".MainActivity" > <RadioGroup android:id="@+id/group1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <RadioButton android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="A" /> <RadioButton android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="B" /> </RadioGroup> <RadioGroup android:id="@+id/group2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:orientation="vertical" > <RadioButton android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="C" /> <RadioButton android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="D" /> </RadioGroup></LinearLayout>package com.example.testgroup;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.widget.RadioButton;import android.widget.RadioGroup;public class MainActivity extends Activity { private RadioGroup group1; private RadioGroup group2; private RadioButton btn1; private RadioButton btn2; private RadioButton btn3; private RadioButton btn4; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); group1 = (RadioGroup) findViewById(R.id.group1); group2 = (RadioGroup) findViewById(R.id.group2); btn1 = (RadioButton) findViewById(R.id.btn1); btn2 = (RadioButton) findViewById(R.id.btn2); btn3 = (RadioButton) findViewById(R.id.btn3); btn4 = (RadioButton) findViewById(R.id.btn4); group1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if (checkedId == btn1.getId()) { System.out.println("a checked"); btn3.setChecked(true); } else if (checkedId == btn2.getId()) { System.out.println("b checked"); btn4.setChecked(true); } } }); } @Override public 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; }} android如何实现通话录音功能 webview先刷新页面后加载资源? Android 如何实现读U盘 关于百度地图的两个问题 HTC one X 拍摄视频为什么帧数只有23fps,不是说30fps吗? 新手求解,每次启动模拟器,都出现这个 eclipse+maven+android整合问题 关于listview的item内部操作问题求助 Windows下搭建Android CTS环境 招聘android高级开发-苏州昆山 Android 动画移动控件后,控件失去焦点,求求帮助! 关于调用百度地图应用的开发
CheckBox才是多选吧。
class RadioGroupLisener implements OnCheckedChangeListener{ @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId==maleButton.getId())
{
System.out.println("选中male");
CButton.setChecked(true);
}
else if (checkedId==famaleButton.getId())
{
System.out.println("选中famale");
}
}
}
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" > <RadioGroup
android:id="@+id/group1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" > <RadioButton
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A" /> <RadioButton
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B" />
</RadioGroup> <RadioGroup
android:id="@+id/group2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="vertical" > <RadioButton
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C" /> <RadioButton
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="D" />
</RadioGroup></LinearLayout>package com.example.testgroup;import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.RadioButton;
import android.widget.RadioGroup;public class MainActivity extends Activity {
private RadioGroup group1;
private RadioGroup group2; private RadioButton btn1;
private RadioButton btn2;
private RadioButton btn3;
private RadioButton btn4; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); group1 = (RadioGroup) findViewById(R.id.group1);
group2 = (RadioGroup) findViewById(R.id.group2);
btn1 = (RadioButton) findViewById(R.id.btn1);
btn2 = (RadioButton) findViewById(R.id.btn2);
btn3 = (RadioButton) findViewById(R.id.btn3);
btn4 = (RadioButton) findViewById(R.id.btn4);
group1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if (checkedId == btn1.getId()) {
System.out.println("a checked");
btn3.setChecked(true);
} else if (checkedId == btn2.getId()) {
System.out.println("b checked");
btn4.setChecked(true);
}
}
}); } @Override
public 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;
}}