0
我試圖攔截拖動事件以及同一視圖上的雙擊事件,從而可以將視圖拖到放置位置,或者如果用戶雙擊相同視圖,則可以打開對話框。問題是在設置View.DragShadowBuilder(view)後,使用SimpleOnGestureListener攔截MotionEvent.ACTION_DOWN事件時,onDoubleTap從不會被調用。有關如何讓視圖被拖動以及雙擊的任何想法?我想可能是取消view.startDrag在SimpleOnGestureListener的MotionEvent.ACTION_CANCEL或onSingleTapUp方法上,但到目前爲止,我還沒有想出一種方法來取消拖動,如果這可以工作。謝謝。雙擊並拖動同一視圖上的偵聽器?
在適配器getView:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
// AlbumHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
}
final GestureDetector gdt = new GestureDetector(getActivity(),new GestureListener(textview,storyItem));
textview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
action = event.getActionMasked();
return gdt.onTouchEvent(event);
}
});
在活動之外適配器:
private class GestureListener extends SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
ClipData data = ClipData.newPlainText("", "");
DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, shadowBuilder, view, 0);
return true;
}
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e){
Toast.makeText(getActivity(), "double tapped", Toast.LENGTH_SHORT).show();
showDialog();
return true ;
}
}