使用java在android中双击问题
Posted
技术标签:
【中文标题】使用java在android中双击问题【英文标题】:Double Click Problem in android with java 【发布时间】:2022-01-09 12:29:08 【问题描述】:我已经为双击创建了一个 Java 类,但我无法双击该项目,因为当我只单击一次时,该项目不会等待双击!
双击类代码
package com.programiner.studyvillaadmin.Classes.Listener;
import android.view.View;
public abstract class DoubleClickListener implements View.OnClickListener
private static final long DOUBLE_CLICK_TIME_DELTA = 300;//milliseconds
long lastClickTime = 0;
@Override
public void onClick(View v)
long clickTime = System.currentTimeMillis();
if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA)
onDoubleClick(v);
lastClickTime = 0;
else
onSingleClick(v);
lastClickTime = clickTime;
public abstract void onSingleClick(View v);
public abstract void onDoubleClick(View v);
【问题讨论】:
请参考***.com/questions/15353457/… 【参考方案1】:private long mLastClickTime = 0;
@Override
public void onClick(View v)
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) //*1000 is time to perform second click*
return; *// return when second click happen in second*
mLastClickTime = SystemClock.elapsedRealtime();
GameSound.getInstance(getApplicationContext()).sound__(GameSound.buttonClick);
if (v == findViewById(R.id.tvUsername))
StartActivity(UserProfile.class);
示例
public long mLastClickTime = 0;
//声明和定义public
holder.itemView.setOnClickListener(new View.OnClickListener() //click lister of itemview of RV Adapter
@Override
public void onClick(View v)
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) //*1000 is time to perform second click*
return; // return when second click happen in second*
mLastClickTime = SystemClock.elapsedRealtime();
//do stuff here...
);
【讨论】:
作为初学者!你能不能把你答案的全部代码提供给我,并展示如何在 RV 适配器中实现这个类 好的,请检查我编辑的答案。 不明白的请参考此链接code.tutsplus.com/tutorials/…以上是关于使用java在android中双击问题的主要内容,如果未能解决你的问题,请参考以下文章
在 Mac OS X 中双击文档文件以打开 Java 应用程序