0
我創建擴展列表和設置gesturedetector這就像滑塊(它顯示和隱藏每次我讓一扔就可以了時間)。廣東話妥善管理onTouchEventListteners在expandableListView
expListListener= new GestureDetector.SimpleOnGestureListener(){
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
expandableListView.invalidateViews();
Thread closeSliderThread = new Thread(new closingSlider());
Thread openingSliderThread = new Thread(new openingSlider());
if (e1.getX() - e2.getX() < 0 && Math.abs(e2.getX() - e1.getX()) > difference) {
closeSliderThread.start();
for (int i = 0; i < expandableListView.getCount(); i++) expandableListView.collapseGroup(i);
return true;
}
if (e2.getX() - e1.getX() > 0
&& Math.abs(e1.getX() - e2.getX()) > difference)
{
openingSliderThread.start();
return true;
}
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
class closingSlider implements Runnable{
@Override
public void run() {
rightPartLL.post(new Runnable() {
@Override
public void run() {
synchronized (closingSlider.class) {
rightPartLL.startAnimation(hide_slider);
}
}
});
}
}
class openingSlider implements Runnable{
@Override
public void run() {
rightPartLL.post(new Runnable() {
@Override
public void run() {
synchronized (openingSlider.class) {
rightPartLL.startAnimation(show_slider);
}
}
});
}
}
然後
gestureDetectorOfExpListView = new GestureDetector(activity,expListListener);
在這裏,我告訴expanableList聽在我的衝動行爲:
expandableListView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return gestureDetectorOfExpListView.onTouchEvent(motionEvent);
}
});enter code here
但是,當我試圖以長期接觸後,來實現邏輯設置OnItemLongListener ExpandableList的孩子:
expandableListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPosition = ExpandableListView.getPackedPositionGroup(id);
int childPosition = ExpandableListView.getPackedPositionChild(id);
Toast.makeText(activity,"group: "+groupPosition +" child:"+childPosition,5000).show();
// Return true as we are handling the event.
return true;
}
return false;
}
});
enter code here
...它不`噸work.But當我再刪除線時,我真想
OnTouchEvent to expandableListView which return return gestureDetectorOfExpListView.onTouchEvent(motionEvent);
.... OnItemLongClickListener
正常工作!幫助我弄清楚如何實現雙手勢動作和onLongTouches
。感謝您的幫助。