android--Custom events for custom components

Source: Internet
Author: User

Mybotton.java

    /*Defining Interfaces*/       Public Interfacemyclick{ Public voidOnmyclick (String str); }      /*Initializing interface Variables*/Myclick Myclick=NULL; /*Custom Events*/       Public voidSetonmyclicklistener (Myclick myclick) { This. myclick=Myclick; }  

Mainactivity.java

Xxx.setonmyclicklistener (Mybotton. Myclick () {                            @Override                The abstract method in the public void Onmyclick (String str) {  //replication interface.                Textview1.settext (str);              }          );  

The Setonmyclicklistener () method needs to implement the above interface.

Class Ongesturelistener

Gesturedetector.ontouchevent (event);

Motionevent

Onsingletapup

Onshowpress

Onlongpress

The following two annotated methods are also frequently used

Invalidate (); If you have other needs draw call this method will excite OnDRAW

Postinvalidate (); Use in other non-main threads to prevent ANR

Layoutinflater.from (context). Inflater (R.layout.xxx.xml,this,true);

Custom properties File: Attrs.xml

<?XML version= "1.0" encoding= "Utf-8"?><Resources>    <!--Custom Properties -    <declare-styleablename= "Header">        <attrname= "Titletextsize"format= "Dimension" />        <attrname= "Titletextcolor"format= "Color" />        <attrname= "TitleText"format= "string"/>    </declare-styleable></Resources>

android--Custom events for custom components

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.