Android Dev _ About click events

Source: Internet
Author: User

To prevent users or test mm from frantically clicking on a button:

Create a tool class Public classTools {Private Static LongLastclicktime;  Public Static BooleanIsfastdoubleclick () {LongTime =System.currenttimemillis (); if(Time-lastclicktime < 500) {               return true; } lastclicktime=Time ; return false; }} when using the Public voidOnClick (View v) {if(Tools. Isfastdoubleclick ()) {return; }}

Multiple clicks to achieve different functions:

//Implement a button listener implementation class, and define tag variables in the implementation class, and execute different methods depending on the value of the variable. //Example:        intFlag = 0;//Defining Tag VariablesButton btn = (button) Findviewbyid (r.id.xxx);//Get buttonBtn.setonclicklistener (NewView.onclicklistener () {//Click Implementation class@Override Public voidOnClick (View v) {if(flag==0){                   //Execution Method 1 (corresponding function 1)}Else if(flag==1){                   //Execution Method 2 (corresponding function 2)}Else if(flag==2){                   //Execution Method 3 (corresponding function 3)} flag= (flag+1)%3;//the rest gets looped to perform the above 3 different functions            }        });

Android Dev _ About click events

Related Article

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.