I have a scrollview with multiple relativelayout views horizontally... one for each record in a database... that are created programmatically.
I need to determine which view is affected by some gestures... click, doubleclick, and left/right swipe.
Of course the CLICK I was able to get with:
RelativeLayout rlView = new RelativeLayout(this);
rlView.setId(10000+myrecordid);
rlView.setOnClickListener(myviewclick);
and the myviewclick:
private View.OnClickListener myviewclick = new View.OnClickListener() {
public void onClick(View v) {
Integer i=v.getId()-10000;
// Do some processing on this view
}
};
From what I found online, I tried to get the gesture this way:
rlView.setOnTouchListener(myviewtouch);
with this code:
private View.OnTouchListener myviewtouch = new View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
Log.i("MYLOG","double tap");
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Log.i("MYLOG","SingleTapConfirmed");
return true;
}
@Override
public void onLongPress(MotionEvent e) {
Log.i("MYLOG","LongPress");
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e1.getX()<e2.getX())
Log.i("MYLOG","Fling Right");
else
Log.i("MYLOG","Fling Left");
return true;
}
});
};
According to MYLOG, I am getting the appropriate gestures as needed. The problem is, I don't know how to get the views ID that the gesture was in. I know it is in the onTouch
but that called the gestureDetector.OnTouchEvent
to determine the motion... and I am lost at this point.
I searched all over StackOverflow and other sites for several hours... they all show variances on how to determine the gesture... but having trouble finding anything about using with multiple views that I can use.
Any help would be appreciated.