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

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
主站蜘蛛池模板: 克东县| 厦门市| 滨州市| 银川市| 宁夏| 敦煌市| 荆门市| 隆昌县| 新沂市| 富宁县| 毕节市| 阿拉善盟| 定结县| 隆化县| 徐水县| 保亭| 道真| 廉江市| 增城市| 保靖县| 邳州市| 长宁县| 长治市| 洛南县| 寿光市| 剑阁县| 镇安县| 东平县| 于田县| 广宗县| 保康县| 维西| 城固县| 方正县| 兴山县| 林口县| 周至县| 麻江县| 大安市| 图木舒克市| 鄂温|