使用手势可以很好解决这个问题
package com.kohler.launcher.view; import com.kohler.launcher.R; import com.library.util.LogUtil; import android.content.Context; import android.gesture.GestureOverlayView; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.widget.ListView; public class CalendarListView extends ListView implements OnGestureListener { public interface LongOnClickCallback { public void onLongOnClick(); public void onClick(); } private LongOnClickCallback callback; public void setCallback(LongOnClickCallback callback) { this.callback = callback; } public CalendarListView(Context context) { super(context); init(); } public CalendarListView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public CalendarListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } private void init() { detector = new GestureDetector(getContext(), this); } private GestureDetector detector; @Override public boolean dispatchTouchEvent(MotionEvent ev) { detector.onTouchEvent(ev); return super.dispatchTouchEvent(ev); } @Override public boolean onDown(MotionEvent e) { return false; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } @Override public void onLongPress(MotionEvent e) { // LogUtil.e(" CalendarListView 长按事件"); //长按模式 if (callback != null) { callback.onLongOnClick(); } } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // LogUtil.e(" CalendarListView onScroll"); return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onSingleTapUp(MotionEvent e) { LogUtil.e(" CalendarListView 点击事件"); if (callback != null) { callback.onClick(); }O return false; } }
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦