Android - Gesture Detection (Swipe up/down) on particular view -
Android - Gesture Detection (Swipe up/down) on particular view -
i trying implement ongesturelistener in android. i have 3 textviews in layout. what trying accomplish set gesture listener 2 of textviews . here layout -
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rlmain" android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/tvone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_marginbottom="10dp" android:layout_margintop="5dp" android:gravity="center" android:text="one" /> <textview android:id="@+id/tvtwo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/tvone" android:layout_centerhorizontal="true" android:layout_marginbottom="10dp" android:layout_margintop="5dp" android:gravity="center" android:text="two" /> <textview android:id="@+id/tvthree" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/tvtwo" android:layout_centerhorizontal="true" android:layout_marginbottom="10dp" android:layout_margintop="5dp" android:gravity="center" android:text="three" />
and here activity -
import android.app.activity; import android.os.bundle; import android.util.log; import android.view.gesturedetector; import android.view.gesturedetector.ongesturelistener; import android.view.motionevent; public class timeactivity extends activity implements ongesturelistener { gesturedetector gesturescanner; @suppresswarnings("deprecation") @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.wheelview); gesturescanner = new gesturedetector(this); } @override public boolean ontouchevent(motionevent event) { // todo auto-generated method stub homecoming gesturescanner.ontouchevent(event); } @override public boolean ondown(motionevent e) { // todo auto-generated method stub homecoming true; } @override public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) { // todo auto-generated method stub log.i("test", "on fling"); homecoming true; } @override public void onlongpress(motionevent e) { // todo auto-generated method stub } @override public boolean onscroll(motionevent e1, motionevent e2, float distancex, float distancey) { // todo auto-generated method stub homecoming false; } @override public void onshowpress(motionevent e) { // todo auto-generated method stub } @override public boolean onsingletapup(motionevent e) { // todo auto-generated method stub homecoming false; }
}
at nowadays fling 3 textviews getting called . there way through can set gesture listener particular views in layout. help highly appreciated.
do in oncreate
method.
findviewbyid(r.id.tvone).setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event){ homecoming gesturescanner.ontouchevent(event); } });
android swipe gesture-recognition onfling
Comments
Post a Comment