Android Development Learning Path-use of basic events

Source: Internet
Author: User

1. How the event responds.

Setonclicklistener (view. Onclicklistener l);

Setonfocuschangelistener (View.onfocuschangelistener L)

Setonlongclicklistener (view. Ononclicklistener l);

Setontouchlistener (view. Ontouchlisterner l);

Three ways to respond to events.

The first way:

Final Button Button1 = (Button) Findviewbyid (R.id.button1);

Button1.setonclicklistener (New Onclicklistener () {

public void OnClick (View V) {

Text.set ...;

}

});

The second way:

When defining a class, extend Activity implements Onclicklistener,

Add event Button1.setonclicklistener to the button (this);

Implements the event onclick, public void onclick (View v)

{

Switch (V.getid ()) {

Case

Break

Default

Break

}

}

The third Way: not commonly used.

2. Keyboard response events, i.e. keys

Boolean onKeyDown (int keycode, keyevent msg);

3. Touch Events

Ontouchevent (Motionevent event)

Getaction (); GetX (); GetY () respectively is to get the corresponding action, already coordinates the position.

How to draw:

1. Define a Paint class container, paint class can set the color of paint, Paint.setcolor (color.red); The paint here is the equivalent of a pen, with what color of the pen, what shape of the pen, to paint.

2. Overloaded OnDraw function protect void OnDraw (canvas canvas)//canvas is a canvas

Canvas.drawcircle (X,y,radiu,paint)//indicates, respectively, the horizontal ordinate, radius, and paint brush of the drawing point.

4. Jump and event transfer between screens

Android Development Learning Path-use of basic events

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.