java - How to set OnTouchListener for the entire screen? -


please have @ following code. posting important sections of code.

activity_game.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/fullview"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".game" >      <textview         android:id="@+id/numberofquestionsleft"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="20dp"         android:text="textview" /> </relativelayout> 

game.java

public class game extends activity {        private view fullview;  @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_game);          fullview = (view)findviewbyid(r.id.fullview);         fullview.setontouchlistener(imageviewswiped);        }    ontouchlistener imageviewswiped = new onswipetouchlistener()     {          public boolean onswiperight()           {             //code removed          }            public boolean onswipeleft()            {              //code removed                 return true;           }            public boolean onswipebottom()           {               //code removed               return true;           }       }; } 

onswiptouchlistener.java

note - not own class of code. written member.

  package game.game;     import android.view.gesturedetector;     import android.view.gesturedetector.simpleongesturelistener;     import android.view.motionevent;     import android.view.view;     import android.view.view.ontouchlistener;      public class onswipetouchlistener implements ontouchlistener {          private final gesturedetector gesturedetector = new gesturedetector(new gesturelistener());          public boolean ontouch(final view v, final motionevent event) {             return gesturedetector.ontouchevent(event);         }          private final class gesturelistener extends simpleongesturelistener {              private static final int swipe_threshold = 100;             private static final int swipe_velocity_threshold = 100;              @override             public boolean ondown(motionevent e) {                 return super.ondown(e);             }              @override             public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {                 boolean result = false;                 try {                     float diffy = e2.gety() - e1.gety();                     float diffx = e2.getx() - e1.getx();                     if (math.abs(diffx) > math.abs(diffy)) {                         if (math.abs(diffx) > swipe_threshold && math.abs(velocityx) > swipe_velocity_threshold) {                             if (diffx > 0) {                                 result = onswiperight();                             } else {                                 result = onswipeleft();                             }                         }                     } else {                         if (math.abs(diffy) > swipe_threshold && math.abs(velocityy) > swipe_velocity_threshold) {                             if (diffy > 0) {                                 result = onswipebottom();                             } else {                                 result = onswipetop();                             }                         }                     }                 } catch (exception exception) {                     exception.printstacktrace();                 }                 return result;             }         }          public boolean onswiperight() {             return false;         }          public boolean onswipeleft() {             return false;         }          public boolean onswipetop() {             return false;         }          public boolean onswipebottom() {             return false;         }     } 

now, trying make make whole activity touched enabled. please view game.java see how did it. problem is, not reacting kind of touch event! there nothing wrong code onswiptouchlistener.java because have used touch events of setting listener image view. there must problem trying make whole activity touch enabled. saying "whole activity touch enabled" mean is, need swipe across whole screen instead of adding listener imageview.

what have done wrong here? please help!

as requested questioner , solution @ answers question ontouchlistener-doesnt-work-with-relative-layout


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -