控件:RadioButton  CheckedBox  RatingBar  ProgressBar

下拉列表:ListView Spinner

 <!-- 单选按钮必须放在单选按钮组当中才能生效 ,并且需要为每一个控件指定id
(html:<input name="sex"/>男 <input name="sex"/>女)
-->
<RadioGroup
android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<RadioButton
android:id="@+id/rb_man"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
/>
<RadioButton
android:id="@+id/rb_woman"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
android:checked="true"
/>
</RadioGroup> <!-- 增加复选框控件 -->
<CheckBox
android:id="@+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="看NBA"
/> <CheckBox
android:id="@+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="逛街"
android:checked="true"
/>
<CheckBox
android:id="@+id/cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="睡觉"
/>
<!-- 增加RadtingBar
numStars:当前有几个RatingBar
rating:当前默认选中几个RatingBar
-->
<RatingBar
android:id="@+id/rbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3"
android:stepSize="1"
/>

布局

 /**
* 单选按钮和监听
* 复选框和监听
* RatingBar和监听
*/ //在处理单选按钮监听的时候不需要分别去处理每一个控件
//只需要处理当前控件所在的组.
//【打印输出最好是不要使用纯数字打印】
//邮件服务器和客户端
//常量值
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
//System.out.println("checkId:"+checkedId);
if(checkedId == R.id.rb_man){
//选择是男
//往界面上输出打印男
//参数1:当前对象
//参数2:输入的内容
//参数3:显示的时间
Toast.makeText(MainActivity.this, "男", Toast.LENGTH_LONG).show();
}else if(R.id.rb_woman == checkedId){
//选择是女
Toast.makeText(MainActivity.this, "女", Toast.LENGTH_SHORT).show();
}
}
}); //监听多选按钮(实现接口的监听的时候需要在前面加上CompoundButton)
cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
Toast.makeText(MainActivity.this, "看NBA", 1).show();
}
}
}); //监听rbar给出评分
rbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
if(fromUser){
//System.out.println("rating:------->"+rating);
//switch:byte short char int enum String(JDK>=7.0)
if(1==rating){
Toast.makeText(MainActivity.this, "不好吃", 1).show();
}else if(3 == rating){
Toast.makeText(MainActivity.this, "还可以", 1).show();
}else if(5 == rating){
Toast.makeText(MainActivity.this, "美味", 1).show();
}
}
}
});

java代码

Spinner

 mySpinner=(Spinner) findViewById(R.id.mySpinner);

         //数组存放TextView里面的行的数据
List<String> list=new ArrayList<String>();
list.add("向云鹏");
list.add("汪伟");
list.add("朱攀");
list.add("杨洋"); //利用适配器(三个视频)将下拉列表和视图发生关系
ArrayAdapter<String> adapter=
new ArrayAdapter<String>(MainActivity.this, R.layout.items, R.id.tv, list); //将适配器装到下拉列表中
mySpinner.setAdapter(adapter);
//设置标题
mySpinner.setPrompt("武汉科技大学人才榜"); //监听Spinner
mySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String item=parent.getItemAtPosition(position).toString();
System.out.println("选择的是:---------->"+item);
} @Override
public void onNothingSelected(AdapterView<?> parent) {
System.out.println("没有选择");
}
});

Spinner

广播机制:

  1.自定义

    a.程序中注册广播

    b.菜单中注册广播

  2.系统广播(充电,开机)

      系统广播(服务Service)

    

自定义:

例:菜单中注册广播

 /**
* 在菜单中进行广播的注册(eg:发送一个广播有一个接受者可以收到,另外一个收不到)
* 先注册--->发送广播-->接受
*/ //发送广播
Intent in=new Intent();
//增加广播信息的区分
in.setAction(Intent.ACTION_EDIT);
//发送广播
sendBroadcast(in);

BroadCast

//普通类 --变成--> 接受者

//1.继承BroadCastReceiver

//2.实现里面OnReceive方法

//3.在菜单中对接受者进行注册

         <!-- 注册接受者 -->
<receiver
android:name="com.example.mybroadcast1.AReceiver"
>
<intent-filter >
<action android:name="android.intent.action.EDIT"/>
</intent-filter>
</receiver>
<receiver
android:name="com.example.mybroadcast1.BReceiver"
></receiver>

Manifest

例:程序中注册广播

 /**
* 在程序中注册广播
*/
private AReceiver receiver;
protected static final String ACTION_A = "com.example.mybroadcast2.ACTION_A"; //1.注册广播
findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
receiver = new AReceiver();
IntentFilter IF=new IntentFilter();
IF.addAction(ACTION_A);
//注册
registerReceiver(receiver, IF);
}
}); //2.发送广播
findViewById(R.id.button2).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//发送
Intent intent=new Intent();
intent.setAction(ACTION_A);
sendBroadcast(intent);
}
});
//3.撤销广播
findViewById(R.id.button3).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(receiver!=null)
unregisterReceiver(receiver);
}
});

在程序中注册广播

android 05的更多相关文章

  1. android 05 桢布局:FrameLayout 网格布据 GridLayout

    xml文件: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android: ...

  2. Android的各种Drawable 讲解 大全

    Android把可绘制的对象抽象为Drawable,不同的图形图像资源就代表着不同的drawable类型.Android FrameWork提供了一些具体的Drawable实现,通常在代码中都不会直接 ...

  3. Android Drawable 与 LayerList综合汇总

    先看需求.要求这样的效果 上代码 <?xml version="1.0" encoding="utf-8"? > <layer-list xm ...

  4. Android中Drawable分类汇总(上)

    Android把可绘制的对象抽象为Drawable,不同的图形图像资源就代表着不同的drawable类型.Android FrameWork提供了一些具体的Drawable实现,通常在代码中都不会直接 ...

  5. 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面

    [Android UI设计与开发]第05期:引导界面(五)实现应用程序只启动一次引导界面 jingqing 发表于 2013-7-11 14:42:02 浏览(229501) 这篇文章算是对整个引导界 ...

  6. Android Service总结05 之IntentService

    Android Service总结05 之IntentService   版本 版本说明 发布时间 发布人 V1.0 添加了IntentService的介绍和示例 2013-03-17 Skywang ...

  7. 080 01 Android 零基础入门 02 Java面向对象 01 Java面向对象基础 01 初识面向对象 05 单一职责原则

    080 01 Android 零基础入门 02 Java面向对象 01 Java面向对象基础 01 初识面向对象 05 单一职责原则 本文知识点:单一职责原则 说明:因为时间紧张,本人写博客过程中只是 ...

  8. 073 01 Android 零基础入门 01 Java基础语法 09 综合案例-数组移位 05 综合案例-数组移位-主方法功能1和2的实现

    073 01 Android 零基础入门 01 Java基础语法 09 综合案例-数组移位 05 综合案例-数组移位-主方法功能1和2的实现 本文知识点:综合案例-数组移位-主方法功能1和2的实现 说 ...

  9. 067 01 Android 零基础入门 01 Java基础语法 08 Java方法 05 数组作为方法参数

    067 01 Android 零基础入门 01 Java基础语法 08 Java方法 05 数组作为方法参数 本文知识点:数组作为方法参数 说明:因为时间紧张,本人写博客过程中只是对知识点的关键步骤进 ...

随机推荐

  1. 【Linux】鸟哥的Linux私房菜基础学习篇整理(七)

    1. test命令的测试功能.测试的标志:(1)关于文件类型的检测 test [-efdbcSpL] filename-e:该文件名是否存在:-f:该文件名是否为文件:-d:该文件名是否为目录:-b: ...

  2. Dinic 模板

    #include <iostream> #include <cstring> #include <cstdio> #include <queue> us ...

  3. C# dll玩注入!.net运行时库内置!?

    Contents Introduction Back To Fundamentals Load The CLR Fundamentals Advanced DLL Injection Fundamen ...

  4. CodeForces 587A

    题目链接: http://codeforces.com/problemset/problem/587/A 题意: 输入n个数,在这n个数中,寻找有多少个数不能消除掉 消除方法:两个相同的数消除后,生成 ...

  5. PostgreSQL安装详细步骤(windows)

    原文地址:http://blog.chinaunix.net/uid-354915-id-3498734.html PostgreSQL安装:一.windows下安装过程安装介质:postgresql ...

  6. [Locked] Paint House I & II

    Paint House There are a row of n houses, each house can be painted with one of the three colors: red ...

  7. IOS中线程的通信

    一.简单说明 线程间通信:在1个进程中,线程往往不是孤立存在的,多个线程之间需要经常进行通信 线程间通信的体现 1个线程传递数据给另1个线程 在1个线程中执行完特定任务后,转到另1个线程继续执行任务 ...

  8. Struts2接收参数的几种方式

    一.用Action属性 在action里定义要接收的参数,并提供相应的set和get方法. 如: public class LoginAction extends ActionSupport { pr ...

  9. evernote出现"Invalid username and/or password"的情况

    evernote出现"Invalid username and/or password"的情况 evernote挺好用的,可是这几年用下来也遇到过狗血情况,几乎每次都是更新后出状况 ...

  10. Eclipse导入Gradle时报错:SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable

    百度查到http://stackoverflow.com/questions/19794200/gradle-android-and-the-android-home-sdk-location 按照其 ...