android - Trying to implement swipe movement -
public class coursesactivity extends sherlockfragmentactivity {
arraylist<coursedata> mcourseslist = new arraylist<coursedata>(); public courseslistadapter courseslistadapter; public listview mlist; public alertdialog.builder dlgalert; public dialog logindialog; public dialog logindialogoverflow; linearlayout progressbar; static sqlitewebcourse dbhelper; private gesturedetectorcompat mdetector; public final static string extra_message = "com.technion.coolie.webcourse.message"; public coursesactivity() { dbhelper = new sqlitewebcourse(this, "webcouredb", null, 1); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // create list of courses mcourseslist = new arraylist<coursedata>(); setcontentview(r.layout.web_activity_courses); mlist = (listview) findviewbyid(r.id.courses_list); dlgalert = new alertdialog.builder(getapplicationcontext()); if (!coolieaccount.webcourse.isalreadyloggedin()) { logindialog = coolieaccount.webcourse.opensignindialog(this); ondismisslistener dismisslistener = new ondismisslistener() { @override public void ondismiss(dialoginterface dialog) { // check if connection success if (coolieaccount.webcourse.isalreadyloggedin()) { // connection success progressbar = (linearlayout) findviewbyid(r.id.progressbarlayout_courses); progressbar.setvisibility(view.visible); asyncparse<coursedata> = new asyncparse<coursedata>() { @override protected list<coursedata> doinbackground( string... params) { // todo auto-generated method stub try { courselist crl = new courselist( getapplicationcontext()); crl.getcourses(coolieaccount.webcourse .getusername(), coolieaccount.webcourse .getpassword()); mcourseslist = dbhelper .getallcourses(coolieaccount.webcourse .getusername()); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } return super.doinbackground(params); } @override protected void onpostexecute(list<coursedata> result) { // todo auto-generated method stub courseslistadapter courseslistadapter = new courseslistadapter( getapplicationcontext(), mcourseslist); mlist.setadapter(courseslistadapter); mlist.setbackgroundcolor(0xfff0f0f0); progressbar.setvisibility(view.invisible); super.onpostexecute(result); } }; a.execute(""); } else { // connection failed log.v("dbass", "second time"); } } }; logindialog.setondismisslistener(dismisslistener); } else { mcourseslist = dbhelper.getallcourses(coolieaccount.webcourse .getusername()); courseslistadapter courseslistadapter = new courseslistadapter( getapplicationcontext(), mcourseslist); mlist.setadapter(courseslistadapter); mlist.setbackgroundcolor(0xfff0f0f0); } log.v("gestures", "ontouchevent@!$#%@#%^&^$%"); // onitemclicklistener itemclicked = new onitemclicklistener() { // // @override // public void onitemclick(adapterview<?> list, view view, // int position, long id) { // // todo auto-generated method stub // loadcourseinformationactivity(((coursedata) mlist // .getitematposition(position)).coursedescription); // } // }; // mlist.setonitemclicklistener(itemclicked); mdetector = new gesturedetectorcompat(this, new mygesturelistener()); } @override public boolean ontouchevent(motionevent event) { log.v("gestures", "ontouchevent@!$#%@#%^&^$%"); this.mdetector.ontouchevent(event); // sure call superclass implementation return super.ontouchevent(event); } class mygesturelistener extends gesturedetector.simpleongesturelistener { private static final string debug_tag = "gestures"; @override public boolean onfling(motionevent event1, motionevent event2, float velocityx, float velocityy) { log.v(debug_tag, "onfling: " + event1.tostring() + event2.tostring()); toast.maketext(getapplicationcontext(), "swiped", toast.length_long) .show(); if (event2.getx() - event1.getx() > swipe_min_distance && math.abs(velocityx) > swipe_threshold_velocity) toast.maketext(getapplicationcontext(), "swiped", toast.length_long).show(); // if (showdeletebutton(e1)) // return true; return super.onfling(event1, event2, velocityx, velocityy); } }
}
hey fellas, i'm trying implement swipe detection went through android lesson , did written there: http://developer.android.com/training/gestures/detector.html reason when touch screen doesnt go ontouchevent. seems problem?
you haven't set touch listener listview
.
listview.setontouchlistener(this);
Comments
Post a Comment