android 常用控件之 (RadioButton) 的使用
来源:互联网 发布:羽毛球编排软件 编辑:程序博客网 时间:2024/05/16 05:43
xml:
<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" android:paddingBottom="0dp" android:paddingLeft="0dp" android:paddingRight="0dp" android:paddingTop="0dp" tools:context=".MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:id="@+id/tupian" android:layout_width="match_parent" android:layout_height="60dp" android:src="@drawable/bee" /> <RadioGroup android:id="@+id/xuanzezu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" > <RadioButton android:id="@+id/on" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="开灯" /> <RadioButton android:id="@+id/off" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="关灯楼" /> </RadioGroup> </LinearLayout></RelativeLayout>
package com.example.mytool;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemSelectedListener;import android.widget.ArrayAdapter;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.ImageView;import android.widget.RadioButton;import android.widget.Spinner;import android.widget.TextView;import android.widget.ToggleButton;public class MainActivity extends Activity {private ImageView imgview;private RadioButton rbtn;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imgview = (ImageView)this.findViewById(R.id.tupian);rbtn=(RadioButton)this.findViewById(R.id.off);rbtn.setOnCheckedChangeListener(new dianji());}private class dianji implements OnCheckedChangeListener{@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {// TODO Auto-generated method stubif(buttonView instanceof RadioButton){rbtn.setChecked(isChecked);imgview.setImageResource(isChecked ? R.drawable.ic_launcher : R.drawable.bee );}}}@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);return true;}}
0 0
- android 常用控件之 (RadioButton) 的使用
- Android之RadioButton控件使用
- (转)android常用控件(二) RadioGroup RadioButton CheckBox Toast的使用
- Android控件系列之RadioButton与RadioGroup的基本使用
- Android控件之Button,RadioButton,CheckBox,DatePicker,DatePickerDialog的使用
- 【读书笔记《Android游戏编程之从零开始》】4.Android 游戏开发常用的系统控件(EditText、CheckBox、Radiobutton)
- Android常用控件八之使用RadioButton切换图片,代码实例
- Android 基本控件的使用三(RadioButton)
- Android开发中单选框控件RadioButton的使用
- android中控件RadioButton的使用
- Android开发之四(五):常用控件之单项选择(RadioGroup和RadioButton)
- Android 控件开发之 RadioButton
- android控件之radiobutton checkbox
- android自定义控件之radioButton
- android 控件之RadioGroup&RadioButton
- Android 控件开发之 RadioButton
- Android控件之RadioGroup、RadioButton
- Android控件之CheckBox、RadioButton
- Groovy HttpBuilder以及Java的URI
- 致垂直电商们:谁无暴风劲雨时,守得云开见月明
- Java设计模式---模板模式
- qemu核心机制分析-协程coroutine
- 关于找不到gsl共享库的问题
- android 常用控件之 (RadioButton) 的使用
- poj 1260(简单动态规划)
- WordPress 3.9使用PostgreSQL数据库问题的解决
- 使用KeyChain保存和获取UDID(唯一标示)
- MyBatis学习之三--动态SQL语句
- 【python 编程】网页中文过滤分词及词频统计
- c++ 单例模式
- Remove Duplicates from Sorted Array II
- C#关键字-where(泛型类型约束)