当前位置:网站首页>RadioGroup(单选框)
RadioGroup(单选框)
2022-07-27 17:02:00 【Ashurol】
public class MainActivity extends ActionBarActivity implements OnCheckedChangeListener{
RadioGroup rp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rp=(RadioGroup) findViewById(R.id.radioGroup1);
rp.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup arg0, int CheckedId) {
// TODO Auto-generated method stub
switch(CheckedId)
{
case R.id.radio0:
Toast.makeText(this, "你是男孩", Toast.LENGTH_SHORT).show();
break;
case R.id.radio1:
Toast.makeText(this, "你是女孩", Toast.LENGTH_SHORT).show();
break;
}
}
}记得别导包android.widget.RadioGroup.OnCheckedChangeListener<pre name="code" class="html"><RelativeLayout 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"
tools:context="com.example.xin.radiogroup.MainActivity" >
<RadioGroup
android:id="@+id/radioGroup1"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="14dp" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="男" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
</RadioGroup>
</RelativeLayout>

边栏推荐
猜你喜欢

二叉搜索树

一种比读写锁更快的锁,还不赶紧认识一下

Complex number proof of solvability of regular 17 sided ruler and gauge drawing

influxDB系列(四)TSM引擎(存储原理)

C language: 10. Input stream, output stream, error stream

A low code development platform that brings high-value user experience

IEC104 规约详细解读(一) 协议结构

Cumulative output data of kettle Excel

C language: 13. Pointer and memory

c语言:c语言代码风格
随机推荐
Low code implementation exploration (45) business parameters
揭秘高通超声波指纹被“贴膜破解”之谜
[Huawei cloud stack] [shelf presence] issue 13: have you seen the decoupling architecture of the management area? Help government and enterprise customers solve big problems
Anaconda下安装Talib库
C language: 6. Simple use and precautions of pointer
细数国产接口协作平台的六把武器!
Complex number proof of solvability of regular 17 sided ruler and gauge drawing
HDU1171_ Big event in HDU [01 backpack]
Make your chat bubbles colorful
Under the heat wave of Web3.0, the ecological shock of Mensa struck
查看宝塔PHP扩展目录
Release Samsung 3J1 sensor: the code implies that the safety of pixel 7 face recognition will be greatly increased
[daily accumulation - 06] view CUDA and cudnn versions
Introduction to Flink operator
The first Xiaolong 765G! Redmi K30 5g release: support 5g dual-mode 120Hz screen, priced from 1999 yuan
Embedded C language loop deployment
IEC104 规约详细解读(一) 协议结构
Embedded C language pointer alias
[basic knowledge of deep learning - 45] distance calculation methods commonly used in machine learning
Basic knowledge of C language (for personal use)