java - OnTouchListener is not getting fired -
please have @ following code
xml code
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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=".paragraphreader" > <scrollview android:id="@+id/paragraph_reader_scroll_view" android:layout_width="match_parent" android:layout_height="wrap_content" > <textview android:id="@+id/paragraph_reader_txt" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="30" android:singleline="false" android:enabled="true" > </textview> </scrollview> </relativelayout>
java code
package k.k; import java.util.arraylist; import java.util.list; import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.view.ontouchlistener; import android.widget.edittext; import android.widget.textview; import android.widget.toast; public class paragraphreader extends activity { private textview paratext; private databaseconnector database; private list<string>paralist; private int currentquestion; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_paragraph_reader); paratext = (textview)findviewbyid(r.id.paragraph_reader_txt); paratext.setontouchlistener(paraswiped); paralist = new arraylist<string>(); database = databasehandler.getinstance(this); //get paragraph list int listnumber = getintent().getintextra("paragraph_list", 0); toast.maketext(this, "selected paragraph: "+listnumber, toast.length_long).show(); paralist = database.getparagraphlist(listnumber); toast.maketext(this, "paralist size "+paralist.size(), toast.length_long).show(); //toast.maketext(this, "size: "+paralist.size(), toast.length_long).show(); paratext.settext(paralist.get(0)); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.paragraph_reader, menu); return true; } //the event handler paragraph text holder ontouchlistener paraswiped = new onswipetouchlistener() { public boolean onswiperight() { toast.maketext(paragraphreader.this, "right: "+paralist.size(), toast.length_short).show(); return true; } public boolean onswipeleft() { toast.maketext(paragraphreader.this, "left: "+paralist.size(), toast.length_short).show(); return true; } }; }
here, can see have implemented ontouchlistener
textview
. below code ontouchlistener
class. code built 1 of member.
package k.k; 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; } }
i need left , right swipes, due t reason, swipong not working. yes, not working, means nothing happening. not understand how correct this. know code developed member working because using in activity.
pleae help.
you might try making text view clickable android:clickable="true". not sure fix problem it's worth shot. i'm not sure android:enabled might doing same thing
Comments
Post a Comment