カレンダー グリッド ビューにタッチ リスナーが必要でした。カレンダー上でドラッグしてデータを取得する onTouch メソッドと、エントリを削除する onDoubleTapEvent が必要です。これを行うために、SimpleOnGestureListener を拡張するカスタム クラス MyGestureListener も実装しました。コードの一部を以下に示します。
calendarGridView.setOnTouchListener(new MyGestureListener(getApplicationContext()) {
//Touch Listener on every gridcell
public boolean onTouch(View v, MotionEvent event) {
super.onTouch(v, event);
....
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
....
}
case MotionEvent.ACTION_UP : {
....
}
case MotionEvent.ACTION_CANCEL: {
....
}
}
//Save the data
return true;
}
public boolean onDoubleTapEvent(MotionEvent event) {
.... //delete the entry, save data
return true;
}
カスタム ジェスチャ リスナー クラス:
public class MyGestureListener extends SimpleOnGestureListener implements OnTouchListener{
Context context;
GestureDetector gDetector;
public MyGestureListener(Context context) {
super();
if (gDetector == null) {
gDetector = new GestureDetector(context, this);
}
this.context = context;
}
public MyGestureListener(Context context, GestureDetector gDetector) {
if (gDetector == null) {
gDetector = new GestureDetector(context, this);
}
this.context = context;
this.gDetector = gDetector;
}
public boolean onTouch(View v, MotionEvent event) {
return gDetector.onTouchEvent(event);
}
public GestureDetector getDetector() {
return gDetector;
}
}
ここでの問題は、カレンダー セルをダブルタップすると、onDoubleTapEvent だけでなく onTouch メソッドも呼び出されることです (ACTION_DOWN、ACTION_UP、および再び ACTION_DOWN、ACTION_UP を考慮)。どうすればそれらを分離できますか?