日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

安卓学习-界面-ui-RadioButton CheckBox

發布時間:2025/5/22 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓学习-界面-ui-RadioButton CheckBox 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

RadioButton ?CheckBox

?

下面例子演示了2個功能,一個是RadioButton選擇時的事件,還有一個是Button按鈕點擊查看這2個控件的屬性

?

XML代碼

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_margin="10dp"><TableLayoutandroid:layout_width="match_parent"android:layout_height="match_parent" ><TableRowandroid:id="@+id/tableRow1"android:layout_width="wrap_content"android:layout_height="wrap_content" ><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:text="性別"android:textAppearance="?android:attr/textAppearanceLarge" /><RadioGroupandroid:id="@+id/radioGroup1"><RadioButtonandroid:id="@+id/radioButton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="男" /><RadioButtonandroid:id="@+id/radioButton2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="女" /></RadioGroup></TableRow><TableRowandroid:id="@+id/tableRow3"android:layout_width="wrap_content"android:layout_height="wrap_content" ><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="是否本地人"android:textAppearance="?android:attr/textAppearanceLarge" /><CheckBoxandroid:id="@+id/checkBox1"android:layout_width="wrap_content"android:layout_height="wrap_content" /></TableRow><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="確定" /></TableLayout></RelativeLayout>

?

java代碼

public class MainActivity extends Activity {Button btn;RadioGroup radioGroup1;CheckBox checkBox1;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn=(Button)findViewById(R.id.button1);radioGroup1=(RadioGroup)findViewById(R.id.radioGroup1);checkBox1=(CheckBox)findViewById(R.id.checkBox1);//按鈕點擊事件btn.setOnClickListener(new OnClickListener() {public void onClick(View v) {int checkedId=radioGroup1.getCheckedRadioButtonId();if(checkedId>0){RadioButton r=(RadioButton)findViewById(checkedId);Toast.makeText(getApplicationContext(), r.getText(), Toast.LENGTH_SHORT).show();}Toast.makeText(getApplicationContext(), ""+checkBox1.isChecked(), Toast.LENGTH_SHORT).show();}});//radioGruop的選擇事件radioGroup1.setOnCheckedChangeListener(new OnCheckedChangeListener() {public void onCheckedChanged(RadioGroup group, int checkedId) {RadioButton r=(RadioButton)findViewById(checkedId);Toast.makeText(getApplicationContext(), "你選擇的是"+r.getText(), Toast.LENGTH_SHORT).show();}});} }

?

轉載于:https://www.cnblogs.com/weijj/p/3946221.html

總結

以上是生活随笔為你收集整理的安卓学习-界面-ui-RadioButton CheckBox的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。