xml

------------------------

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/TextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
/>
<CheckBox android:id="@+id/CheckBox1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/CheckBox1"
></CheckBox>
<CheckBox android:id="@+id/CheckBox2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/CheckBox2"
></CheckBox>
<CheckBox
android:id="@+id/CheckBox3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/CheckBox3"
/>
</LinearLayout>

java

--------------------

package com.example.huanglifeng.menudemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;


public class MainActivity extends Activity{

CheckBox m_CheckBox1;
CheckBox m_CheckBox2;
CheckBox m_CheckBox3;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

m_CheckBox1=(CheckBox)findViewById(R.id.CheckBox1);
m_CheckBox2=(CheckBox)findViewById(R.id.CheckBox2);
m_CheckBox3=(CheckBox)findViewById(R.id.CheckBox3);


final CheckBox.OnCheckedChangeListener btnListener=new CheckBox.OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
{
int num=0;
String strTmp="";
if(m_CheckBox1.isChecked())
{
num++;
strTmp+=m_CheckBox1.getText()+"\n";
}
if(m_CheckBox2.isChecked())
{
num++;
strTmp+=m_CheckBox2.getText()+"\n";
}
if(m_CheckBox3.isChecked())
{
num++;
strTmp+=m_CheckBox3.getText()+"\n";
}
strTmp="你选择了"+num+"项,他们分别是:"+"\n"+strTmp;
DisplayToast(strTmp);
}
};


m_CheckBox1.setOnCheckedChangeListener(btnListener);
m_CheckBox2.setOnCheckedChangeListener(btnListener);
m_CheckBox3.setOnCheckedChangeListener(btnListener);
}
public void DisplayToast(String str)
{
Toast toast=Toast.makeText(this,str,Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP,0,220);
toast.show();
}
}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android开发仿IOS滑动开关
  2. Android(安卓)开发环境下载地址 -- 百度
  3. android_防止被反编译 混淆
  4. Android Studio 如何引用aar包
  5. Google android初级开发之 : android 编
  6. Android 设定横屏,禁止屏幕旋转,Activity重
  7. 关于Android Studio 模拟器“ANDROID SDK
  8. android基本知识
  9. Android(安卓)Dalvik ART
  10. 框架模式MVC与MVP在Android中的应用