码迷,mamicode.com
首页 > 移动开发 > 详细

android 事件

时间:2015-01-06 23:17:40      阅读:408      评论:0      收藏:0      [点我收藏+]

标签:

Android不允许在其他线程中直接更新界面组件。需要借助Handler对象间接实现。
安卓提供了两种方式的事件处理——回调与监听。

监听

想让一个控件响应单击事件,那么需要做两步。1.编写监听器,记为类A,实现单击事件监听器接口;2.对控件设置它的监听器,与类A关联起来。

android.os.Bundle
保存从String类型到各种类型的映射。
A mapping from String values to various Parcelable types. 
void android.os.BaseBundle.putString(String key, String value)
放入String类型的键值对。
Inserts a String value into the mapping of this Bundle。
String android.os.BaseBundle.getString(String key)
返回Bundle中设置的与key对应的value。
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

android.os.Handler
处理消息的类。
void android.os.Handler.handleMessage(Message msg)
定义了收到消息后要做哪些事。该方法需要被重写。
boolean android.os.Handler.sendMessage(Message msg)
将一个消息推送到消息队列的尾部。
Pushes a message onto the end of the message queue。

android.os.Message
用于发送给Handler处理的消息。
Bundle android.os.Message.getData()
获取消息中的Bundle.
Obtains a Bundle of arbitrary data associated with this event。


sample

在输入框内输入123,点击button,左上方的TextView会显示输入框内的内容。
技术分享

android 事件

标签:

原文地址:http://blog.csdn.net/chuchus/article/details/42464235

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!