Android Callback event Propagation-android learning Journey (45)

Source: Internet
Author: User

Concept Introduction

Code Demo
 PackagePeng.liu.test;ImportAndroid.app.ActionBar;Importandroid.app.Activity;ImportAndroid.graphics.Color;ImportAndroid.os.Bundle;ImportAndroid.util.DisplayMetrics;ImportAndroid.view.Display;ImportAndroid.view.KeyEvent;ImportAndroid.view.Menu;ImportAndroid.view.View;ImportAndroid.view.Window;ImportAndroid.view.WindowManager;ImportAndroid.widget.Button; Public  class mainactivity extends Activity{    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main); Findviewbyid (R.id.mybutton). Setonkeylistener (NewView.onkeylistener () {@Override             Public Boolean OnKey(View view,intI, KeyEvent keyevent) {System.out.println ("Listener on Listener");return false;    }        }); }@Override     Public Boolean OnKeyDown(intKeyCode, KeyEvent event) {Super. OnKeyDown (KeyCode, event); System.out.println ("Listener on Activity");return false; }}
 PackagePeng.liu.test;ImportAndroid.content.Context;ImportAndroid.content.SyncStatusObserver;ImportAndroid.util.AttributeSet;ImportAndroid.view.KeyEvent;ImportAndroid.widget.Button;/** * Created by LPLP on 2015/6/10. * * Public  class MyButton extends Button{     Public MyButton(Context context,attributeset AttributeSet) {Super(Context,attributeset); }@Override     Public Boolean OnKeyDown(intKeyCode, KeyEvent event) {Super. OnKeyDown (KeyCode, event); System.out.println ("Listener on button");return false; }}
<?xml version= "1.0" encoding= "Utf-8"?><linearlayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  xmlns:tools  =" Http://schemas.android.com/tools " android:layout_width  = "match_parent"  android:layout_height  =" match_parent " android:orientation  =;     <Peng.liu.test.MyButtonandroid:layout_width="Fill_parent"android:layout_ Height="Wrap_content"android:id="@+id/mybutton" />                        </linearlayout>
Print order

Listener on Listener
Listener on Button
Listener on Activit
The listener that first went to the binding, then to the button replication callback, and finally to the acticity implementation.

Android Callback event Propagation-android learning Journey (45)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.