I create my own calendar view that extends LinearLayout and has child views for each date. What I want to do is process the napkins and click, as you can imagine, swipe your finger over the month and press to select a date and display the new activity. For this, I use the GestureDetector for CalendarView and I can make it work for scrolling. But to handle the click event, I don't know how to find the child view that clicked.
- Does anyone have an idea to solve this?
- What is the difference between return true and false in OnScroll (MotionEvent)?
The following is part of my codes.
public class MonthView extends LinearLayout implements GestureDetector.OnGestureListener {
public MonthView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
gestureDetector = new GestureDetector(this);
initDateViews();
}
....
private void initDateViews() {
for(int i = 0; i < 42; i++) {
DateView view = new DateView();
....
calendar.Add(view);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Logger.debug(TAG, ">>> MonthView.onTouchEvent()");
return gestureDetector.onTouchEvent(event);
}
@Override
public boolean OnSingleTapUp(MotionEvent event) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (e1.getX() - e2.getX() > minSwipeDistance) {
this.prevMonth();
}
else if(e2.getX() - e1.getX() > minSwipeDistance) {
this.nextMonth();
}
else if(e1.getY() - e2.getY() > minSwipeDistance) {
this.prevMonth();
}
else if(e2.getY() - e1.getY() > minSwipeDistance) {
this.nextMonth();
}
return false;
}
....
}