日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/5/22 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓学习-界面-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的全部內容,希望文章能夠幫你解決所遇到的問題。

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