In my application i have a button. After single and double clicking of the button will perform separate operation. How can i do that? Thanks
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You may need to create a delay variable which will differenciate between single click and double click.
See this code,
You may want to consider not using a DoubleTap. It is not a normal Android behavior.
When I first started programming on the Android, I kept running into things that were really "hard" to do on the android. Over time, I've found that many of them were difficult because they were a pretty bad idea.
If you are porting an iOS app, or emulating an iOS app's behavior, you may want to consider converting the UI over to Android style behaviors and use a longPress or other 'androidy' gestures.
Here is a similar question and answer:
Android: How to detect double-tap?
Though it's too late, but anyone can figure out if they see this.
Explanation:
Before the button click, number_of_click is initialized to 0. thread_started is a flag detecting if the thread is started before or not. Now, on button click, increase the number of button click by incremental operator. check if the thread is previously started or not, if not, then start the thread. on thread, apply your logic by using the number_of_clicks. and the thread will wait for next milliseconds and then will go through your logic. So, now you can apply as many clicks as you want.
You have to implement GestureDetector and put your code in
single/double click
.TestActivity.java
Now you have to create
GestureDetector.java
class.The up solution cannot work for multi click, i test it but failed.
So i suggest to use RxBinding with ProgressDialog.
when click button, the progressDialog show setting it cannot be cancel, Fix it.
Solving this by inherit from the View.OnClickListener and checking the click time to distinguish the single click or double click, this also solve the problem of fast clicking. This solution will bring minor code change, just replace View.OnClickLister. You also can override the getGap() to redefine the time between two clicks.