導航:首頁 > 操作系統 > 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相關的資料

熱點內容
android開機黑屏 瀏覽:566
mc純生存伺服器是什麼意思 瀏覽:438
樹莓派火焰蜂鳴器python 瀏覽:896
我的世界伺服器強制疾跑怎麼開 瀏覽:275
用什麼app看施工圖紙 瀏覽:491
張三學python函數 瀏覽:377
女子程序員照片 瀏覽:305
武漢c程序員招聘 瀏覽:681
csk跟蹤演算法 瀏覽:24
數據挖掘中用到的演算法 瀏覽:843
更改ubuntu伺服器地址 瀏覽:502
學做燒菜用什麼app 瀏覽:702
程序框圖怎麼加密 瀏覽:372
文件自解壓失敗怎麼辦 瀏覽:899
ug操作和產品命令 瀏覽:79
QQ在線表格怎麼加密 瀏覽:484
steam星際戰甲什麼伺服器 瀏覽:596
python重啟路由器腳本 瀏覽:821
java聊天窗口 瀏覽:978
單片機控制陣列led燈 瀏覽:579