107.android最简单的双击监听,双击事件

//双击监听类:

public class DoubleClick {

    private static DoubleClick doubleClick;
    private final Handler handler;

    public static DoubleClick getInstance() {
        if (doubleClick == null) {
            doubleClick = new DoubleClick();
        }
        return doubleClick;
    }

    private DoubleClick() {
        handler = new Handler();
    }

    /**
     * 单击双击事件接口
     */
    public interface OnDoubleClickListener {
        void onDoubleClick(View v);
    }


    /**
     * 通过Handler延时发送判断是否双击
     *
     * @param view
     * @param listener
     */
    public void doubleClickListener(View view, final OnDoubleClickListener listener) {
        if (listener == null) {
            return;
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (handler.hasMessages(0)) {
                    //执行双击
                    listener.onDoubleClick(v);
                } else {
                    handler.sendEmptyMessageDelayed(0, 350);
                }
            }
        });
    }

}

 

//使用方式:

//双击监听 回到列表顶部
DoubleClick.getInstance().doubleClickListener(mHomeActivityRecently, new DoubleClick.OnDoubleClickListener() {
    @Override
    public void onDoubleClick(View v) {
        mHomePhoneRecy.smoothScrollToPosition(0);
    }
});

 

//--------------------------------------------------------------------------------完---------------------------------------------------------------------------------

 

 

你可能感兴趣的:(android效果,android)