Android Ontouchlistener For Entire Dialog
I have a dialog to choose files from. This dialog contains a listview to show directories and files and has an onItemClickListener for navigation purposes. How can I react to fling
Solution 1:
You should create a class which extends the dialog class and then you can create a gesture detector and attach to the ontouchevent of the class. Here is a code example:
publicclassGestureDialogextendsDialog {
publicGestureDialog(Context context, int theme) {
super(context, theme);
gestDetec = newMyGestureDetector(); //inital setup
gestureDetector = newGestureDetector(gestDetec);
gestureListener = newView.OnTouchListener() {
publicbooleanonTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
returntrue;
}
returnfalse;
}
};
}
@OverridepublicbooleanonTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event))
returntrue;
elsereturnfalse;
}
classMyGestureDetectorextendsSimpleOnGestureListener {
@OverridepublicbooleanonFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
System.out.println( "Help im being touched!" );
returnfalse;
}
}
}
Post a Comment for "Android Ontouchlistener For Entire Dialog"