如何将文本设置为radiobutton,该文本通过编程性的放射线群架内部?

2024-03-21

我有一个RadioGroup我有一些RadioButtons.

我想在RadioButton以编程方式。我使用以下代码,我无法访问RadioButtonS内部RadioGroup使用Java。

我该如何将文本设置在RadioButton里面一个RadioGroup?

XML 布局:

<RadioGroup android:layout_width="fill_parent"
    android:layout_marginLeft="20dip"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/QueGroup1">

    <RadioButton android:checked="false"
        android:button="@drawable/green"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:textColor="#000"
        android:text="Yes"
        android:id="@+id/rbtnYes"
        android:visibility="gone" />

    <RadioButton android:checked="false"
        android:button="@drawable/red"
        android:textColor="#000"
        android:text="No"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" 
        android:id="@+id/rbtnNo"
        android:visibility="gone" />

    <RadioButton android:checked="false"
        android:button="@drawable/red"
        android:textColor="#000"
        android:text="Dont Know"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:id="@+id/rbtnDontKnow"
        android:visibility="gone" />
</RadioGroup>

Java代码:

private void fnRadioTextSet(String strval) {
    rbtnYes = (RadioButton)findViewById(R.id.rbtnYes);
    rbtnNo = (RadioButton)findViewById(R.id.rbtnNo);
    rbtnDontKnow = (RadioButton)findViewById(R.id.rbtnDontKnow);
    RadioGroup rbtnGrp = (RadioGroup)findViewById(R.id.QueGroup1);
    String[] strArrtext = strval.split(",");
    for (int intcount = 0; intcount < strArrtext.length; intcount++) {
        rbtnGrp.getChildAt(intcount).settext("test");
    }

    //int i = rbtnGrp.getChildCount();
    //Toast.makeText(getApplication(), rbtnGrp.getChildCount(),
    //      Toast.LENGTH_LONG).show();
    /*String[] strtext = strval.split(",");
    if (strtext.length > 0) {

    }*/
}

private void fnRadioTextSet(String strval) {
    RadioGroup rbtnGrp = (RadioGroup)findViewById(R.id.QueGroup1);
    String[] strArrtext = strval.split(",");
    for (int i = 0; i < rbtnGrp.getChildCount(); i++) {
        ((RadioButton) rbtnGrp.getChildAt(i)).setText(strArrtext[i]);
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将文本设置为radiobutton,该文本通过编程性的放射线群架内部? 的相关文章

随机推荐