I have a scrollview with several horizontal relativelayout views ... one for each record in the database ... which are created programmatically.
I need to determine what kind of gestures affect the look ... click, double click and scroll left / right.
Of course, CLICK, which I could contact:
RelativeLayout rlView = new RelativeLayout(this); rlView.setId(10000+myrecordid); rlView.setOnClickListener(myviewclick);
and myviewclick:
private View.OnClickListener myviewclick = new View.OnClickListener() { public void onClick(View v) { Integer i=v.getId()-10000;
From what I found on the Internet, I tried to make a gesture like this:
rlView.setOnTouchListener(myviewtouch);
using 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 get appropriate gestures as needed. The problem is that I do not know how to get the identifier of the view in which this gesture was. I know that it is in onTouch , but called gestureDetector.OnTouchEvent to determine the movement ... and I got lost at that point.
I searched all StackOverflow and other sites for several hours ... they all show deviations in how to define a gesture ... but without having problems finding any problems using several kinds that I can use.
Any help would be greatly appreciated.