Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid How do I write a simple timer for UI events?
    primarykey
    data
    text
    <p>My app needs to check whether user double clicks or not. But I can't use Android OnDoubleClickListener or something likes that. Just implements it :</p> <p>My problem is diferent from "normal" double click.</p> <p>What I want is: If user double clicks, run the Y activity. If user clicks 1 click only, wait 500 ms then run the X activity. If user click 2 click slowly, run the X activity</p> <p>This is my code:</p> <pre><code> long now = System.currentTimeMillis(); thisTime = now; if (thisTime - lastTouchTime &lt; WAIT_TIME) { // Double tap this.getContext() .getApplicationContext() .startActivity( (new Intent(getContext(), ChangePlaceActivity.class)) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); // If is double tap, reset to start state. lastTouchTime = -1; return true; } else { // Too slow or first click // If not double tap, save last state for next check lastTouchTime = thisTime; Log.d("Worker thread", "Declare" + System.currentTimeMillis()); Thread t = new Thread() { public void run() { try { sleep(WAIT_TIME); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; t.start(); try { t.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d("Worker thread", "" + System.currentTimeMillis()); // start MainAct Log.d("Single Click", "Yes"); this.getContext() .getApplicationContext() .startActivity( (new Intent(getContext(), MainActivity.class)) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } </code></pre> <p>If use code like this, I can't got double click. If remove thread.run() thread.join(). It will start MainActivity before ChangePlacecActivity.</p> <p>Is there any solution for this problems? Thank you in advance!</p> <p>Sorry for my bad English.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload