1
我實現ExpandableListView DragNDrop使用此源https://github.com/sreekumarsh/android/tree/master/Drag%20N%20Drop子項。所有的主要功能是在課堂上,它擴展ExpandableListView。它覆蓋onTouchEvent(MotionEvent事件)方法,並且我指示的長按功能如下:並不總是工作在ExpandableListView子項長按
int flatPosition = pointToPosition(x, y);
dragRatio = getHeight()/screenHeight;
long packagedPosition = getExpandableListPosition(flatPosition);
Runnable mLongPressed = new Runnable() {
public void run() {
event.setLocation(x, y);
touchHandler(event);
pressedItem = true;
}
};
if (action == MotionEvent.ACTION_DOWN
&& getPackedPositionType(packagedPosition) == 1) {
if (dragOnLongPress) {
if (pressedItem) {
mDragMode = true;
pressedItem = false;
} else {
pressedItem = true;
**handler.postDelayed(mLongPressed, 500);**
return true;
}
} else if (x < dragOffset) {
mDragMode = true;
}
}
但是,有一些問題。長時間點擊並不總是。我怎樣才能做到這一點更可靠的(不使用GestureDetector類)。
你是不是總是工作是什麼意思?你期望的行爲是什麼? – DawidPi
當檢測到長按,我設置的標誌,和未來在行動的依賴性,我選擇或移動子項。如果可以,在我的問題打開鏈接,發現類DragNDropListView。它擁有touchHandler方法中的所有代碼。謝謝 –