我是android新手,在android中使用mysql工作测验应用程序项目。我想动态设置单选按钮的文本。如何访问radiogroup的单个单选按钮,设置.java文件中每个单选按钮的文本?请帮助我解决这个问题。提前致谢。在Android中动态设置单选按钮的文本
0
A
回答
0
在youe xml文件中创建单选按钮。获取应用程序mainActivity中的单选按钮。
RadioButton rb1 =(RadioButton)findViewById(R.id.radioButton1);
更改使用以下梅托德
rb1.setText("new text");
this is how a xml of radio group looks like
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/radioButton2"
android:layout_below="@+id/radioButton2"
android:layout_marginTop="58dp" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
to access each radio button of a group you can use its name
example radio0,radio1,radio2 are the three radio buttons in a radio group
you can access it by
RadioButton rb0 = (RadioButton) findViewById(R.id.radio0);
rb0.setText("new text");
+0
如何访问一个radiogroup的单个单选按钮? –
+0
这是如何在xml中创建一个收音机组 – subbu147
2
RadioGroup mGroup = (RadioGroup) findViewById(R.id.radioGroup1);
int count = mGroup.getChildCount();
for(int i = 0;i<count;i++){
if(mGroup.getChildAt(i) instanceof RadioButton)
((RadioButton) mGroup.getChildAt(i)).setText("Radio Button "+i);
}
与按钮相关的文字我希望这会帮助你。让我知道发生了什么事。
相关问题
- 1. 单选按钮的动态设置
- 2. 设置单选按钮文本
- 3. 动态单选按钮文本对齐
- 4. 在动作中设置按钮文本
- 5. 需要在布局中动态设置单选按钮horizontaly:android
- 6. 动态设置单选按钮活动使用jQuery的移动
- 7. 在按钮上动态设置EditText中的文本点击
- 8. Android的 - 动态单选按钮问题
- 9. 如何在jQuery单选按钮组中设置活动的单选按钮
- 10. 在动态创建的字段上设置单选按钮值
- 11. 动态单选按钮设置添加列表项的选择
- 12. 如何在android中动态创建的按钮上设置radom文本?
- 13. 在jquery中动态设置按钮文本
- 14. Mootools的设置单选按钮选中
- 15. Android动态单选按钮获取值
- 16. 添加单选按钮动态︰android
- 17. 通过CFLOOP动态设置单选按钮状态
- 18. 设置动态文本中的Android
- 19. 的Android组单选按钮文本
- 20. 在按钮对象内设置动态文本字段的值
- 21. 如何在Android中按下按钮时设置单选按钮的文本颜色?
- 22. 是否可以在XML中动态设置Android按钮文本大小?
- 23. 按钮单击时设置单选按钮被选中为真
- 24. 设置android:背景正在搞乱我的单选按钮的文本
- 25. 如何动态设置单选按钮的'checked'属性。
- 26. 如何将动态创建的单选按钮设置为RadioGroup?
- 27. 使用ng-repeat设置动态单选按钮的值
- 28. 单选按钮未设置为选中
- 29. 设置默认选中单选按钮
- 30. jQuery设置单选按钮
使用rb.setText(“text”); – jyomin