山寨开机选择四大系统-----------RadioGroup 、RadioButton单选按钮
来源:互联网 发布:如何选择电视机 知乎 编辑:程序博客网 时间:2024/05/30 05:16
以下是java 文件
public class Activity01 extends Activity {/** * 创建TextView对象 * 创建RadioGroup对象 * 创建4个RadioButton对象 */TextView m_T; RadioGroup m_RG; RadioButton m_R1, m_R2, m_R3, m_R4; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /** * 获得TextView对象 * 获得RadioGroup对象 * 获得4个RadioButton对象 */ m_T = (TextView)findViewById(R.id.TextView01); m_RG =(RadioGroup)findViewById(R.id.RadioGroup01); m_R1=(RadioButton)findViewById(R.id.RadioButton01); m_R2 =(RadioButton)findViewById(R.id.RadioButton02); m_R3 =(RadioButton)findViewById(R.id.RadioButton03); m_R4 =(RadioButton)findViewById(R.id.RadioButton04); /* 设置事件监听 */ m_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ public void onCheckedChanged(RadioGroup group, int checkedId){ if(checkedId == m_R2.getId()){ DisplayToast("恭喜你" + m_R2.getText()+ ",进入iphone4系统中~~~~"); }else{ DisplayToast("系统错误,该系统已损坏!"); } } }); } public void DisplayToast(String str){ Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG); //设置toast显示的位置 Gravity 重力 toast.setGravity(Gravity.TOP, 0, 220); //显示该Toast toast.show(); } }
以下是UI的XML文件
<?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" > <TextView android:id = "@+id/TextView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <!-- 单选组框 --> <!-- 选项按钮RadioButton --> <RadioGroup android:id = "@+id/RadioGroup01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/RadioGroup01" > <RadioButton android:id="@+id/RadioButton01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/RadioButton01" /> <RadioButton android:id = "@+id/RadioButton02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/RadioButton02" /> <RadioButton android:id = "@+id/RadioButton03" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/RadioButton03" /> <RadioButton android:id = "@+id/RadioButton04" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/RadioButton04" /> </RadioGroup> </LinearLayout>
以下是string .xml里面的
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">选择进入系统</string> <string name="app_name">系统选择</string> <string name="RadioGroup01">RadioGroup01</string> <string name="RadioButton01">android2.3.3</string> <string name="RadioButton02">iphone4</string> <string name="RadioButton03">windowPhone8</string> <string name="RadioButton04">塞班系统</string> </resources>
运行图片后为:
选择iPhone4 则显示
- 山寨开机选择四大系统-----------RadioGroup 、RadioButton单选按钮
- 单选按钮RadioButton&RadioGroup
- 单选按钮RadioGroup与RadioButton实例
- android 单选按钮 RadioGroup RadioButton
- RadioButton单选按钮实现RadioGroup.OnCheckedChangeListener
- 单选按钮RadioGroup和RadioButton
- 安卓控件之单选按钮 (RadioButton和RadioGroup)
- 单选框RadioGroup,单选按钮RadioButton的使用
- 单选框RadioGroup,单选按钮RadioButton的使用
- RadioGroup、RadioButton(单选按钮)、CheckBox(多选按钮)和Toast的使用方法
- 单选选择RadioGroup
- RadioButton单选按钮
- RadioButton单选按钮
- RadioButton单选按钮
- RadioButton单选按钮
- 单选按钮RadioButton
- 单选按钮RadioButton
- RadioButton单选按钮
- 关于APACHE 无权限访问的问题 403 解决方案
- Ideal education
- Android之gallery
- cygwin完整版下载地址
- CSMA/CD CSMA/CA
- 山寨开机选择四大系统-----------RadioGroup 、RadioButton单选按钮
- 魔术师发牌问题C++实现
- HTTP服务七层架构技术探讨
- 程序员怎样读书
- scrollView的几个属性contentSize contentOffset contentInset
- Linuc--C--getchar
- poj3292
- linux--C--getch
- 内存交换空间的构建(swap)