RadioButton
来源:互联网 发布:网络暴力ppt模板 编辑:程序博客网 时间:2024/05/04 17:21
RadioButton结合RadioGroup实现单项选择
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别" /> <RadioGroup android:id="@+id/sex" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10sp" android:orientation="vertical" > <RadioButton android:id="@+id/nan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" /> <RadioButton android:id="@+id/nv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女" /> </RadioGroup> </LinearLayout> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选择性别" /></LinearLayout>
package com.example.android_radiobutton;import android.os.Bundle;import android.app.Activity;import android.util.Log;import android.view.Menu;import android.view.View;import android.widget.Button;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;public class MainActivity extends Activity {private RadioGroup radioGroup;private Button button;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);radioGroup = (RadioGroup) findViewById(R.id.sex);button = (Button) findViewById(R.id.button1);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubint radioButtonCount=radioGroup.getChildCount();/*for(int i=0;i<radioButtonCount;i++){RadioButton radioButton=(RadioButton) radioGroup.getChildAt(i);String text=radioButton.getText().toString();Toast.makeText(MainActivity.this,text, 1).show();}*/RadioButton radioButton1 = (RadioButton) findViewById(radioGroup.getCheckedRadioButtonId());String text=radioButton1.getText().toString();Toast.makeText(MainActivity.this,text, 1).show();}});return true;}}
0 0
- radiobutton
- radioButton
- Radiobutton
- RadioButton
- RadioButton
- RadioButton
- radiobutton
- RadioButton
- RadioButton
- RadioButton
- Radiobutton
- RadioButton
- RadioButton
- RadioButton
- RadioButton
- RadioButton与自定义RadioButton
- RadioButton控件
- RadioButton 类
- ubuntu opengrok 安装使用
- 生命中最重要的
- 关于“兴趣爱好”之我见
- 编程珠玑——位图法
- objecive-c java EDS加密 大综合
- RadioButton
- VS2010 项目属性的默认包含路径设置方法
- Unit test
- C#实践与委托详解
- spring MVC 总结
- On-premises software 释义http://en.wikipedia.org/wiki/On-premises_software
- 韦东山stdio裸机程序分析
- 从Proxy-Stub到aidl
- 在Ubuntu 10.04中文版下Qt编程,使用unixODBC和FreeTDS连接MS SQL Server 2005,并且中文不出现乱码的方法