官术网_书友最值得收藏!

Taking Actions

Handling events is an essential part of any application; they are the raw input data for a user interface and how we interact with our users (rather than just presenting them with data). Android has an event model that will be instantly familiar to anyone who has programmed Java on their desktop--you attach listener objects to the widgets, and they deliver events to you.

Event listeners in Android take the form of interfaces that you need to implement in order to receive the events. Each possible event type is declared as a method on the relevant interface. To receive a notification that the user has clicked or tapped on a widget, you use the OnClickListener interface, which declares a method--onClick(View)--which will be invoked when the relevant widget receives what it considers a click gesture from the user.

In this chapter, we'll take a look at events on Android, and how best to implement them. Specifically, we'll be taking a closer look at the following:

  • How Android dispatches events, and how it affects your program and user experience
  • Different ways to implement event listeners and their pros and cons
  • How to wrap groups of events into logical classes
  • How to make events always happen quickly
主站蜘蛛池模板: 广丰县| 双桥区| 城市| 平谷区| 海晏县| 胶南市| 吉木萨尔县| 砚山县| 余江县| 邹城市| 怀柔区| 新郑市| 双柏县| 蓬安县| 桃园县| 喀喇沁旗| 廉江市| 米脂县| 景谷| 汉沽区| 定西市| 库伦旗| 柳林县| 景德镇市| 依兰县| 余江县| 苏尼特右旗| 芒康县| 汉寿县| 仙居县| 黑河市| 乌拉特前旗| 新民市| 吉隆县| 恩平市| 绥芬河市| 昌平区| 社旗县| 囊谦县| 贺州市| 晋中市|