导航:首页 > 操作系统 > android自定义radiogroup

android自定义radiogroup

发布时间:2022-06-13 15:16:27

android radiogroup怎么用

RadioButton和RadioGroup的关系:1、RadioButton表示单个圆形单选框,而RadioGroup是可以容纳多个RadioButton的容器2、每个RadioGroup中的RadioButton同时只能有一个被选中3、不同的RadioGroup中的RadioButton互不相干,即如果组A中有一个选中了,组B中依然可以有一个被选中4、大部分场合下,一个RadioGroup中至少有2个RadioButton5、大部分场合下,一个RadioGroup中的RadioButton默认会有一个被选中,并建议您将它放在RadioGroup中的起始位置。

Ⅱ android开发radiogroup怎么添加其他的控件

radiogroup只能添加radiogbutton哈,是配套使用的控件。

Ⅲ Androidstudio,中找不到Radiogroup的自定义id

单选按钮
在onCreate方法里用
findViewById
示:
radiogroup=(RadioGroup)findViewById(R.id.radioGroupId);
femalebutton=(RadioButton)findViewById(R.id.femaleButtonId);
malebutton=(RadioButton)findViewById(R.id.maleButtonId);

Ⅳ android如何实现代码控制RadioGroup中某一个按钮选中

RadioButton在做表单的时候经常用到,在安卓开发中,RadioButton需要和RadioGroup一起使用,表示在一组可选项中,只有一
个可以被选中,RadioGroup状态改变的一个监视器OnCheckedChangeListener,RadioGroup使用的时候调用
setOnCheckedChangeListener(),然后重写OnCheckedChangeListener中的
onCheckedChanged()方法,比如:

java">radioGroup.setOnCheckedChangeListener(newOnCheckedChangeListener(){
@Override
publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){
//获取变更后的选项的ID
intradioButtonId=group.getCheckedRadioButtonId();
switch(radioButtonId){
caseR.id.message_radiobtn:
mFragment=newMessageFragment();
break;
caseR.id.contact_radiobtn:
mFragment=newContactFragment();
break;
caseR.id.dynamic_radiobtn:
mFragment=newDynamicFragment();
break;
default:
break;
}
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.realtabcontent,mFragment).commit();
}
});

这篇简单写了一个几行代码介绍,实现的效果有点类似QQ底部导航切换,Teachcourse博客:

Ⅳ 请教一个Android方面在Menu菜单里定义的RadioGroup中返回某个RadioButton的选中状态的问题

RadioButton在做表单的时候经常用到,在安卓开发中,RadioButton需要和RadioGroup一起使用,表示在一组可选项中,只有一个可以被选中,RadioGroup状态改变的一个监视器OnCheckedChangeListener,RadioGroup使用的时候调用setOnCheckedChangeListener(),然后重写OnCheckedChangeListener中的onCheckedChanged()方法,比如:
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// 获取变更后的选项的ID
int radioButtonId = group.getCheckedRadioButtonId();
switch (radioButtonId) {
case R.id.message_radiobtn:
mFragment = new MessageFragment();
break;
case R.id.contact_radiobtn:
mFragment = new ContactFragment();
break;
case R.id.dynamic_radiobtn:
mFragment = new DynamicFragment();
break;
default:
break;
}
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.realtabcontent, mFragment).commit();
}
});

Ⅵ Android 谁有动态添加多个RadioGroup 并获取所有RadioGroup被选中的值的方法

private void setListenerForView(){

//选择radio

selectRadioBtn();

//库内上水的监听事件

radioGroup.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override

public void onCheckedChanged(RadioGroup
group, int checkedId) { selectRadioBtn();

}

});

}

private void selectRadioBtn(){

radioButton =
(RadioButton)findViewById(radioGroup.getCheckedRadioButtonId());

waterIn =
radioButton.getText().toString();

Log.i("radio",
waterIn);

}

Ⅶ android 的radiogroup显示多个radiobutton的问题

将<LinearLayout></LinearLayout>去掉就OK了 是你的布局又问题 如下:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<RadioGroup
android:id="@+id/RG"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checkedButton="@+id/b1"
android:orientation="vertical" >

<RadioButton
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="1" />

<RadioButton
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="2" />

<RadioButton
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="3" />

<RadioButton
android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="4" />
</RadioGroup>

</LinearLayout>

希望对LZ有帮助!

Ⅷ android的radiogroup为什么选择两个

项目中遇到多个RadioGroup中单选RadioButton ,设置了默认选中第一个 . 然后就 能选中两个RadioButton . . ..

我开始这样给设置默认选中一个的:

for (int j = 0; j < newList.get(position).getList().size(); j++) {
RadioButton radioButton = new RadioButton(context);
radioButton.setTextSize(9);

radioButton.setText(newList.get(position).getList().get(j)
.get("dishname").toString());
radioButton.setTag(newList.get(position).getList().get(j)
.get("dishid").toString());
radioGroup.addView(radioButton, j);

if (j==0) {
radioButton.setCheck(true);
}
}

就是中给radioButton设置为选中.. .

网上查找了下类似的情况 如 这篇文章 ,都没有解决我的问题.

最后研究了下 android 官方Api 和部分 RadioGroup的源代码 后发现. 其实很简单

我们不需要设置RadioButton的默认选中, 这样会使RadioButton一直处于选中状态.

我们应该给RadioGroup 设置选中的RadioButton ,也就是说

把 if (j==0) {
radioButton.setCheck(true);
}

更改为

if (j==0) {
radioGroup.check(radioButton.getId());
}

轻松搞定.. 哎呦了个去,官方Api和源码是个好东西啊.

Ⅸ android的radiogroup怎么移动布局

实际上只要我们明白在radiogroup里面我们也可以使用RelativeLayout,LinearLayout这样的布局的;首先设置radiogroup的orientation属性为vertical

然后再第一个radiobutton前面加上LinearLayout,orientation属性设置为horizontal,</LinearLayout>标签放在一行最后一个radiobutton后面;小编这里是 文本为“50”的那个radiobutton后面

同样的把使用LinearLayout把后面几个radiobutton包裹住,orientation属性设置为horizontal,

运行一下就可以发现就达到了我们想要的结果!

Ⅹ Android如何动态生成Radio和RadioGroup

privateLinearLayoutlayout;//布局,可以在xml布局中获得

privateRadioGroupgroup;//点选按钮组

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

layout=newLinearLayout(this);//实例化布局对象

group=newRadioGroup(this);//实例化单选按钮组

//添加单选按钮

for(inti=0;i<5;i++){

RadioButtonradio=newRadioButton(this);

radio.setText("radio"+i);

group.addView(radio);

}

//将单选按钮组添加到布局中

layout.addView(group);

this.setContentView(layout);

}

可以把单选按钮组放在ScrollView中,这样的话,多出的部分可以滚动查看了。

阅读全文

与android自定义radiogroup相关的资料

热点内容
清大阅读app是什么 浏览:446
怎么用qq浏览器整体解压文件 浏览:584
肺组织压缩15 浏览:269
安卓手机为什么换电话卡没反应 浏览:795
诸子集成pdf 浏览:338
php注册框代码 浏览:716
手机加密好还是不加好好 浏览:814
别克凯越压缩机泵头多钱 浏览:241
组管理命令 浏览:980
海南高德司机端是什么app 浏览:861
pid命令 浏览:888
一天一图学会python可视化 浏览:309
魔兽编辑文本命令串 浏览:497
android中view绘制 浏览:798
安卓机内存删除怎么恢复 浏览:331
Qt环境的编译软件放到linux 浏览:214
联创打印系统怎么连接服务器 浏览:937
杭州行政命令 浏览:160
如何查找服务器日志 浏览:801
加密的钥匙扣怎么写 浏览:579