Android 开发指南 翻译3:User Interface: Input Events
2012-02-04 15:58
465 查看
Android
开发指南 翻译3:User Interface:Input Events
These methods are called by the Android framework when the respective action occurs on that object.
An event listener is an interface in the
that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI.
事件监听器是View的一个接口,包含一个回调方法。当注册了监听器的视图与用户进行交互时,这些回调方法将被Android调用。
例子:
Remember that key events are always delivered to the View currently in focus.
key事件总是分配给当前获得光标的View。
For a touch-capable device, once the user touches the screen, the device will enter touch mode. From this point onward, only Views for which
true will be focusable, such as text editing widgets. Other Views that are touchable, like buttons, will not take focus when touched; they will simply fire their on-click listeners when pressed.
非触摸模式:显示获得焦点的控件,以告知用户当前的焦点。
触摸模式:只有部分控件获得焦点时,才显示给用户。
对与可触摸的设备,用户一旦触摸屏幕,就进入触摸模式。
Any time a user hits a directional key or scrolls with
a trackball, the device will exit touch mode, and find a view to take focus. Now, the user may resume interacting with the user interface without touching the screen.
用户只要使用方向键或滚球,系统退出触摸模式。
Views indicate their willingness to take focus through the
To change whether a View can take focus, call
When in touch mode, you may query whether a View allows focus with
You can change this with
调用isFocusable()是否可以接收光标;setFocusable()设置;在xml中通过
开发指南 翻译3:User Interface:Input Events
These methods are called by the Android framework when the respective action occurs on that object.
Event Listeners
An event listener is an interface in the Viewclass
that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI.
事件监听器是View的一个接口,包含一个回调方法。当注册了监听器的视图与用户进行交互时,这些回调方法将被Android调用。
View.onClickListener | onClick() |
View.OnLongClickListener | onLongClick() |
View.OnFocusChangeListener | onFocusChange() |
View.OnKeyListener. | onKey() |
View.OnTouchListener | onTouch() |
View.OnCreateContextMenuListener | onCreateContextMenu() |
// Create an anonymous implementation of OnClickListener private OnClickListener mCorkyListener = new OnClickListener() { public void onClick(View v) { // do something when the button is clicked } }; protected void onCreate(Bundle savedValues) { ... // Capture our button from layout Button button = (Button)findViewById(R.id.corky); // Register the onClick listener with the implementation above button.setOnClickL d194 istener(mCorkyListener); ... }
Remember that key events are always delivered to the View currently in focus.
key事件总是分配给当前获得光标的View。
Event Handlers
Touch Mode
For a touch-capable device, once the user touches the screen, the device will enter touch mode. From this point onward, only Views for whichisFocusableInTouchMode()is
true will be focusable, such as text editing widgets. Other Views that are touchable, like buttons, will not take focus when touched; they will simply fire their on-click listeners when pressed.
非触摸模式:显示获得焦点的控件,以告知用户当前的焦点。
触摸模式:只有部分控件获得焦点时,才显示给用户。
对与可触摸的设备,用户一旦触摸屏幕,就进入触摸模式。
Any time a user hits a directional key or scrolls with
a trackball, the device will exit touch mode, and find a view to take focus. Now, the user may resume interacting with the user interface without touching the screen.
用户只要使用方向键或滚球,系统退出触摸模式。
Handling Focus
Views indicate their willingness to take focus through the isFocusable()
method.To change whether a View can take focus, call
setFocusable()
.When in touch mode, you may query whether a View allows focus with
isFocusableInTouchMode()
.You can change this with
setFocusableInTouchMode()
.调用isFocusable()是否可以接收光标;setFocusable()设置;在xml中通过
android:focusable设定。
相关文章推荐
- Android开发指南中文版(十)User Interface-Input Events
- Android 开发指南 翻译2 User Interface:XML Layouts
- Android 开发指南 翻译 User Interface -- Dialogs
- Android 开发指南翻译开篇--User Interface -Styles and Themes
- Android 开发指南 翻译10:Intents and Intent Filters
- Android帮助文档翻译——开发指南(一)应用程序基本原理
- Android SDK开发指南(翻译)系列一:最佳实践(二)-- 反应速度设计
- Android 开发指南 翻译6 Accessing Resources
- Android开发指南(38) —— Status Bar Notifications(翻译)
- NDK官方开发指南翻译之 Android.mk
- Android开发指南中文版(十一)User Interface-Menus
- Android开发指南中文版(十二)User Interface-Dialogs
- Android官方开发指南翻译(2)-应用程序基本原理
- Android 开发指南 翻译11 Application Resources -- Drawable Resources
- Android帮助文档翻译——开发指南(三)任务和Back Stack
- Android 开发指南 翻译7 Application Resources: Handling Runtime Changes(未完...)
- Android开发指南中文版(十四)User Interface-Binding to Data with AdapterView
- NDK官方开发指南翻译之 Android.mk
- Android 开发指南 翻译11 Application Resources -- String Resources
- Android官方开发指南翻译(未整理)