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

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
主站蜘蛛池模板: 巴塘县| 镇原县| 巨鹿县| 沁源县| 泽普县| 常宁市| 法库县| 玛曲县| 梧州市| 栾川县| 定边县| 江都市| 循化| 波密县| 池州市| 鸡东县| 巴南区| 通渭县| 津市市| 宝坻区| 龙泉市| 万安县| 白水县| 阿克| 石首市| 长顺县| 博客| 正镶白旗| 扶沟县| 西乌珠穆沁旗| 宜春市| 三门县| 沽源县| 涡阳县| 巩留县| 清镇市| 泰安市| 星子县| 塔城市| 曲阜市| 光泽县|