Android单选按钮RadioButton的使用详解

Android单选按钮RadioButton的使用详解

2023年7月7日发(作者:)

Android单选按钮RadioButton的使⽤详解RadioButton是最普通的UI组件之⼀,继承了Button类,可以直接使⽤Button⽀持的各种属性和⽅法。RadioButton与普通按钮不同的是,它多了⼀个可以选中的功能,可额外指定⼀个android:checked属性,该属性可以指定初始状态时是否被选中,其实也可以不⽤指定,默认初始状态都不选中。使⽤RadioButton必须和单选框RadioGroup⼀起使⽤,在RadioGroup中放置RadioButton,通过setOnCheckedChangeListener( )来响应按钮的事件;(1)选⽤radioGroup的图标 (2)控制的类是package utton;import utton.R;import ;import ty;import ;import ;import utton;import ;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { te(savedInstanceState); setContentView(ty_main); } /* * 设置radio的点击事件,当点击的时候显⽰⽂字 */ public void onRadioButtonClicked(View view) { RadioButton button = (RadioButton) view; boolean isChecked = ked(); switch (()) { case 0: if (isChecked) { xt(, t(), 1).show(); } break; case 1: if (isChecked) { xt(, t(), 1).show(); } break; case 2: if (isChecked) { xt(, t(), 1).show(); } break; default: break; } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(, menu); return true; }}(3)显⽰结果,当点击的时候显⽰⽂字总结以上就是这篇⽂章的全部内容了,希望本⽂的内容对⼤家的学习或者⼯作具有⼀定的参考学习价值,谢谢⼤家对的⽀持。如果你想了解更多相关内容请查看下⾯相关链接

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688677926a161792.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信