自定义一个监听器 NoDoubleItemClickListener,抽象一个 onNoDoubleItemClick 方法。
/** * NoDoubleItemClickListener * * Created by yuzhenbei on 2016/2/15. */ public abstract class NoDoubleItemClickListener implements AdapterView.OnItemClickListener{ /** 连击事件间隔 */ public static final int DELAY = 1000; /** 记录最后一次时间 */ private long mLastClickTime = 0; @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { long _CurrentTime = System.currentTimeMillis(); //判断时间差 if (_CurrentTime - mLastClickTime > DELAY) { //记录最后一次点击时间 mLastClickTime = _CurrentTime; onNoDoubleItemClick(parent, view, position, id); } } /** * 抽象一个无连击事件方法,用于实现内容 * * @param parent * @param view * @param position * @param id */ public abstract void onNoDoubleItemClick(AdapterView<?> parent, View view, int position, long id); } 用法,在建立监听的时候使用刚刚自定义的监听器,并实现其抽象方法。 mListView.setOnItemClickListener(new NoDoubleItemClickListener() { @Override public void onNoDoubleItemClick(AdapterView<?> adapterView, View view, int position, long id) { // } });
文章评论
Great, yahoo took me stright here. thanks btw for this. Cheers!
This helps. Cheers!