Android prevents multiple clicks, causing event listening to respond to other interfaces. android listening

Source: Internet
Author: User

Android prevents multiple clicks, causing event listening to respond to other interfaces. android listening

The following is a case:

Click A to jump to page B. Click B to finish. Return to page.

1. On the page B, set the Click Event and click Finish B.

V. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {B. finish ();}});


2. If you click B multiple times in A row at this time, the system may return A after B ends. The click event is returned to interface A, which leads to repeated display on interface B.

3. To solve this problem, you can use the latency policy. After you click "B" on the page B, the system does not return to interface A immediately. Instead, it sets A latency. After you click it, after A delay of 1000 ms (custom), end B and return to interface. In this way, the click event is displayed in interface A after repeated clicks on interface B.

4. The Code is as follows:

V. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {v. setOnClickListener (null); // The Listener handler whose event needs to be ended here. postDelayed (new Runnable () {@ Overridepublic void run () {B. finish () ;}}, 500 );}});



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.