Skip to content Skip to sidebar Skip to footer

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;
    }
}

}

Solution 2:

You can Take one activity and set it's theme in manifest to dialog.

Then implements onTouchListener to that activty and write one onTouch() event in that Activity.

Now you got Touch event for entire dialog :)

Post a Comment for "Android Ontouchlistener For Entire Dialog"