java - Android drawable swiping not working (from beginners sample code) -


i'm fluent in java years never tried making apps. 2 days ago started , 20 minute work getting android studio on setting in netbeans show hello world app on phone. i'm stuck approach swiping through array of jpg's. app gets build , started, not displaying of pics. please have look.

    package vf.base;  import android.app.activity; import android.content.res.typedarray; import android.os.bundle; import android.view.motionevent; import android.view.viewgroup; import android.widget.imageview; import android.widget.viewflipper;  public class mainactivity extends activity {      private viewflipper viewflipper;     private typedarray pics;     private onswipetouchlistener onswipetouchlistener;      /**      * called when activity first created.      */     @override     protected void oncreate(bundle savedinstancestate) {         pics = getresources().obtaintypedarray(r.array.pics);         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          viewflipper = (viewflipper) findviewbyid(r.id.viewflipper);         (int = 0; < pics.length(); i++) {             addviewflipper(i);         }          onswipetouchlistener = new onswipetouchlistener(this) {             @override             public void onswiperight() {                 viewflipper.shownext();             }              @override             public void onswipeleft() {                 viewflipper.showprevious();             }         };          viewflipper.setontouchlistener(onswipetouchlistener);     }      private void addviewflipper(int position) {         imageview imageview = new imageview(mainactivity.this);         imageview.setimageresource(position);         viewgroup.layoutparams imageparams = new viewgroup.layoutparams(                 viewgroup.layoutparams.match_parent,            viewgroup.layoutparams.match_parent);         imageview.setlayoutparams(imageparams);          viewflipper.addview(imageview);     }      @override     public boolean dispatchtouchevent(motionevent ev) {         onswipetouchlistener.gesturedetector.ontouchevent(ev);         return super.dispatchtouchevent(ev);     } } 

.

    package vf.base;  import android.content.context; import android.view.gesturedetector; import android.view.motionevent; import android.view.view;  public class onswipetouchlistener implements view.ontouchlistener {     public gesturedetector gesturedetector;      public onswipetouchlistener(context context) {         gesturedetector = new gesturedetector(context, new gesturelistener());     }      public void onswipeleft() {     }      public void onswiperight() {     }      public boolean ontouch(view v, motionevent event) {         return gesturedetector.ontouchevent(event);     }      private final class gesturelistener extends gesturedetector.simpleongesturelistener {          private static final int swipe_distance_threshold = 100;         private static final int swipe_velocity_threshold = 100;          @override         public boolean ondown(motionevent e) {             return true;         }          @override         public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {             float distancex = e2.getx() - e1.getx();             float distancey = e2.gety() - e1.gety();             if (math.abs(distancex) > math.abs(distancey) && math.abs(distancex) > swipe_distance_threshold                     && math.abs(velocityx) > swipe_velocity_threshold) {                 if (distancex > 0)                     onswiperight();                 else                     onswipeleft();                 return true;             }             return false;         }      } } 

.

    <?xml version="1.0" encoding="utf-8"?> <resources> <integer-array name="pics">     <item>@drawable/tp_001</item>     <item>@drawable/tp_002</item>     <item>@drawable/tp_003</item>  </integer-array> </resources> 

thanks!

edit: layout.xml

    <?xml version="1.0" encoding="utf-8"?> <linearlayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical">      <viewflipper         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:id="@+id/viewflipper"         android:layout_alignparenttop="true"         android:layout_alignparentstart="true" />  </linearlayout> 


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -