20. Double-click the three-click event

Source: Internet
Author: User

  
 
  1. /**
  2. * 模拟双击事件
  3. * @author Kevin
  4. *
  5. */
  6. public class MainActivity extends Activity {
  7. private long firstClickTime;
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_main);
  12. }
  13. public void onClick(View view) {
  14. if (firstClickTime > 0) {// 发现之前点击过一次
  15. Span class= "KWD" >if ( system Span class= "pun". currenttimemillis () - Firstclicktime < 500 ) { //determine if two clicks are less than 500 milliseconds
  16. Toast.makeText(this, "双击啦!", Toast.LENGTH_SHORT).show();
  17. firstClickTime = 0;//重置时间, 重新开始
  18. return;
  19. }
  20. }
  21. firstClickTime = System.currentTimeMillis();
  22. }
  23. }
Three-shot event
  
 
  1. public class MainActivity extends Activity {
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.activity_main);
  6. }
  7. long[] mHits = new long[3];// 数组长度表示要点击的次数
  8. Span class= "KWD" >public void OnClick ( view View ) {
  9. Span class= "Typ" >system arraycopy ( mhits Span class= "lit" >1 mhits Span class= "PLN" > 0 mhits length - 1 );
  10. mHits [ mhits length - 1 ] = systemclock uptimemillis (); //start calculation time after power on
  11. Span class= "KWD" >if ( mhits Span class= "pun" >[ 0 ] >= ( systemclock uptimemillis () - 500 {
  12. Toast.makeText(this, "是男人!!!", Toast.LENGTH_SHORT).show();
  13. }
  14. }
  15. }



From for notes (Wiz)

20. Double-click the three-click event

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.