Android two clicks to start a different activity
I was wandering if it's possible to 开发者_运维技巧count how many times a person has clicked my widget or item. Lets say I wanted to start a Activity on one click but start another on two clicks. How would I do this?
Just keep track of the clicks. Do they need to be clicked within a short amount of time, as in a double click?
If that's the case, just keep track of the last time the button was clicked and evaluate the difference on subsequent clicks. Use System.currentTimeMillis() to get the current timestamp to the millisecond.
To implement the single click, you can use Handler.postDelayed to delay the action of opening the single-click activity. This way, you can use the timeout period to determine if it is indeed a single or double click.
If you simply mean that the first time the user clicks the button it should open one activity and the second time another, you can just flip a boolean switch each time it's clicked and evaluate that boolean at the point of selecting an activity to open.
you have to implement the Double click in your app like Rich says
with this sample you can start a new activity if you click two times in less of 300 ms
long thisTime = System.currentTimeMillis();
if (thisTime - lastTouchTime < 300) {
Intent newIntent = new Intent(MyMainActivity.this, MyNewActivity.class); startActivity(newIntent);
lastTouchTime = -1;
} else {
lastTouchTime = thisTime;
}
精彩评论