android控件之radiobutton checkbox
来源:互联网 发布:评价张作霖 知乎 编辑:程序博客网 时间:2024/05/16 12:54
这里有一个问题,现在还不清楚,为什么这里的toast不能显示呢?
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" ><TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你最喜欢的动物是:"/> <ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp"/><RadioGroup android:id="@+id/radioGroup" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="left"> <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="猫" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="狗" /> </RadioGroup><TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你喜欢的运动是:"/> <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跑步" /> <CheckBox android:id="@+id/checkBox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="游泳" /> </LinearLayout>CheckboxAndRadiobutton.java
package com.android.forlinx;import android.app.Activity;import android.os.Bundle;import android.widget.CheckBox;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.CompoundButton;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;import android.widget.Toast;public class CheckboxAndRadiobutton extends Activity {private ImageView image = null;private RadioGroup mradio = null;private RadioButton rButton1,rButton2;private CheckBox mcheck = null;private CheckBox mcheck2;private TextView mresult = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image = (ImageView)findViewById(R.id.image); mradio = (RadioGroup)findViewById(R.id.radioGroup); rButton1 = (RadioButton)findViewById(R.id.radioButton1); rButton2 = (RadioButton)findViewById(R.id.radioButton2); mcheck = (CheckBox)findViewById(R.id.checkBox1); mcheck2 = (CheckBox)findViewById(R.id.checkBox2); mradio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubif (checkedId == rButton1.getId()){Toast.makeText(CheckboxAndRadiobutton.this, "您最喜欢的动物是"+rButton1.getText(), Toast.LENGTH_LONG);image.setImageResource(R.drawable.p1);}else if(checkedId == rButton2.getId()){Toast.makeText(CheckboxAndRadiobutton.this, "您最喜欢的动物是"+rButton2.getText(), Toast.LENGTH_LONG);image.setImageResource(R.drawable.p2);}}}); mcheck.setOnCheckedChangeListener(listener); mcheck2.setOnCheckedChangeListener(listener); // mradio.set } OnCheckedChangeListener listener = new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif (mcheck.isChecked()){Toast.makeText(CheckboxAndRadiobutton.this, "您喜欢的运动是"+mcheck.getText(), Toast.LENGTH_LONG);//为什么这里的toast不能显示呢?因为在listener中吗?System.out.println("您喜欢的运动是"+mcheck.getText());}else if(mcheck2.isChecked()){System.out.println("您喜欢的运动是"+mcheck2.getText());}}};}效果图:
- android控件之radiobutton checkbox
- Android控件之CheckBox、RadioButton
- Android控件之CheckBox、RadioButton探究
- Android 基础控件之CheckBox与RadioButton
- Android控件之CheckBox、RadioGroup、RadioButton
- Android控件之Checkbox和RadioButton
- Android控件CheckBox、RadioButton
- Android控件CheckBox和RadioButton
- android基本控件RadioButton/CheckBox
- Android控件RadioButton&RadioGroup&CheckBox
- Android常见控件之RadioGroup,RadioButton,CheckBox和Toast
- Android开发--控件之RadioGroup、RadioButton、CheckBox、Toast
- Android控件之Button,RadioButton,CheckBox,DatePicker,DatePickerDialog的使用
- 13-界面控件之RadioButton和CheckBox
- UI控件学习之CheckBox & RadioButton
- android常用控件------checkBox RadioButton ImageView Spinner
- Android-基本控件(CheckBox,RadioGroup,RadioButton)
- Android基础控件 - RadioButton与CheckBox
- Windows 2008 开启 UPNP
- Qt/Embedded GUI移植及应用程序开发
- 教你怎么使用sql游标
- android之ADT解理
- 几分耕耘几分收获
- android控件之radiobutton checkbox
- Linux下双网卡-双外网网关-电信联通双线主机设置
- XML配置实现ASP.NET开发
- PHP相关系列 - PHP中关于COOKIE域问题
- 正则表达式验证代码(字母、数字、Email、网址、电话号码、汉字、身份证号码)
- MINI2440 下对 NandFlash 烧写 和 裸版程序环境搭建初步
- Key_poll_example
- System.load 和 System.loadLibrary详解
- 理想与现实