Can somebody advise how can I detect if the listview swipes out of bounds? I have only one item in the listview. And I need to detect when user swipes it up or down and listview accordingly goes up or down and show empty space above or below it. And in this moment I should to update my listview's adapter and pass new item there.
I tried to implement it with GestureListener like this :
class MyGestureListener extends SimpleOnGestureListener implements OnTouchListener
{
public boolean onDown(MotionEvent arg0) {
InteractionsAdapter adapter = new InteractionsAdapter(InteractionsActivityAlt.this,
R.layout.interactions_item, DashboardActivityAlt.messagesExport,DashboardActivityAlt.messagesExport.size()-2);
adapter.notifyDataSetChanged();
Log.i("asd","sdas");
return true;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if(Math.abs(e1.getY()-e2.getY()) > 250)
return false;
if(e1.getX() - e2.getX() > 120// && Math.abs(velocityX) > 200
){
//mSwipeDetected = Action.RL;
Log.d("one", "Coords: x=" + e1.getX() + ",y=" + e2.getY());
//do something...
return true;
}
else if(e2.getX() - e1.getX() > 120// && Math.abs(velocityX) > 200
){
// mSwipeDetected = Action.LR;
Log.d("two", "Coords: x=" + e1.getX() + ",y=" + e2.getY());
//do something...
return true;
}
return false;
}
public void onLongPress(MotionEvent arg0) {
AlertDialog.Builder builder = new AlertDialog.Builder(InteractionsActivityAlt.this);
builder.setMessage("Are you sure to choose timezone "+" ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float arg2,
float arg3) {
float pos = e2.getY() - e1.getY();
if (pos < -170 & pos > -200)
{
mSwipeDetected = Action.BT;
try {
Log.i("gesturelistener", "Move down");
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (pos > 170 & pos < 200)
{
mSwipeDetected = Action.BT;
try {
Log.i("gesturelistener", "Move up");
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true;
}
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
public boolean onTouchEvent(MotionEvent me)
{
return gestureScanner.onTouchEvent(me);
}
public boolean onTouch(View arg0, MotionEvent arg1) {
if (arg1.getAction()==MotionEvent.ACTION_UP)
arg0.setBackgroundColor(Color.WHITE);
return false;
}
}
It detects swipe up or down actions but not when listview goes out of bounds and show empty space.
I solved my issue with the method:
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}