最近工作中遇到一个给GridView响应双击事件的需求,参照在stackoverflow上查到的一些答案实现了个响应OnItemDoubleClick事件的OnItemClickListener,目前的实现方式就是定义一个实现了OnItemClickListener接口的内部类。下面是代码:
class CustomOnItemClickListener implements OnItemClickListener {
private boolean nonDoubleClick = true;
private long firstClickTime = 0L;
private final int DOUBLE_CLICK_TIMEOUT = 180;//ViewConfiguration.getDoubleTapTimeout();
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
// @TODO check and catch the double click event
synchronized(VibinOnItemClickListener.this) {
if(firstClickTime == 0) {
firstClickTime = SystemClock.elapsedRealtime();
nonDoubleClick = true;
} else {
long deltaTime = SystemClock.elapsedRealtime() - firs