I created Expandable list and set gesturedetector which acts like Slider(it shows and hides every time i make fling on it).
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);
}
}
});
}
}
then
gestureDetectorOfExpListView = new GestureDetector(activity,expListListener);
here i tell the expanableList to listen on my fling actions:
expandableListView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return gestureDetectorOfExpListView.onTouchEvent(motionEvent);
}
});enter code here
But when i tried to set an OnItemLongListener in order to implement logic after long touch the child of 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
...and it doesn`t work.But when i delete then lines where i set
OnTouchEvent to expandableListView which return return gestureDetectorOfExpListView.onTouchEvent(motionEvent);
....OnItemLongClickListener
works properly! Help me to figure out how to implement both- gesture actions and onLongTouches
as well. Thank you for any assistance.
So i found an elegant solution: