android - How to detect single tap on TouchImageView in ViewPager? -


i made app in displaying images inside viewpager. using universal image loader. images loading fine, , can zoom in , out because have added touchimageview imageview. when single tap on screen want display buttons, such share , delete. not able detect single touch gestures. why?

code viewpager

public class imageviewpager extends activity {         // declare variable         int position;         button delete, gimmy, done;         viewpager viewpager;         imagepageradapter pageradapter;         touchimageview imageview;         textview text;         runnable r;         handler mhandler;         relativelayout rel;         gesturedetector gesturedetector;          @suppresslint("newapi")         @override         public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             // set title viewpager             setcontentview(r.layout.view_pager);             mhandler=new handler();             delete=(button) findviewbyid(r.id.del);             done=(button) findviewbyid(r.id.done);             gimmy=(button) findviewbyid(r.id.gimmy);             rel=(relativelayout)findviewbyid(r.id.relative);             actionbar bar = getactionbar();             bar.setdisplayhomeasupenabled(true);             bar.sethomebuttonenabled(true);             settitle("viewpager");             intent p = getintent();             position = p.getextras().getint("id");             pageradapter = new imagepageradapter(imageviewpager.this);             viewpager = (viewpager) findviewbyid(r.id.pager);             viewpager.setadapter(pageradapter);             viewpager.setcurrentitem(position);               r=new runnable() {                   @override                   public void run() {                      // todo auto-generated method stub                      delete.setvisibility(view.gone);                      done.setvisibility(view.gone);                      gimmy.setvisibility(view.gone);                   }                     };               mhandler.postdelayed(r,5*1000);               done.setonclicklistener(new onclicklistener() {                     @override                     public void onclick(view v) {                          intent p = new intent(getapplicationcontext(), mainactivity.class);                          startactivity(p);                     }                 });               gimmy.setonclicklistener(new onclicklistener() {                      @override                     public void onclick(view v) {                      }                 });               delete.setonclicklistener(new onclicklistener() {                       @override                     public void onclick(view v) {                          }                     });               viewpager.setonpagechangelistener(new onpagechangelistener() {                       @override                     public void onpageselected (int page)                     {                          delete.setvisibility(view.gone);                          done.setvisibility(view.gone);                          gimmy.setvisibility(view.gone);                     }                      @override                     public void onpagescrolled (int arg0, float arg1, int arg2)                     {                      }                      @override                     public void onpagescrollstatechanged (int arg0)                     {                     }                  });           }           @override         public boolean onoptionsitemselected(menuitem item) {             // todo auto-generated method stub              switch (item.getitemid()) {             case android.r.id.home:                  finish();                 overridependingtransition(r.anim.slide_enter, r.anim.slide_exit);                 return true;              default:                 return super.onoptionsitemselected(item);              }          }           @override         public boolean onkeydown(int keycode, keyevent event) {             if (keycode == keyevent.keycode_back) {                 intent p = new intent(getapplicationcontext(), slideimages.class);                 // p.putextra("id", pos+1);                 startactivity(p);             }              return super.onkeydown(keycode, event);         } } 

code pager adapter

public class imagepageradapter extends pageradapter {     layoutinflater inflater;     photoviewattacher attacher;     private displayimageoptions options;     private  list<wallpaper>  images_list=appcontroller.getinstance().getprefmanger().getallimages();           public imagepageradapter(context context)          {                 inflater = layoutinflater.from(context);                  options = new displayimageoptions.builder()                 .showimageforemptyuri(r.drawable.ic_empty)                 .showimageonfail(r.drawable.ic_error)                 .resetviewbeforeloading(true)                 .cacheondisk(true)                 .imagescaletype(imagescaletype.exactly)                 .bitmapconfig(bitmap.config.rgb_565)                 .considerexifparams(true)                 .displayer(new fadeinbitmapdisplayer(300))                 .build();         }      @override     public object instantiateitem(viewgroup container, int position)     {         view imagelayout = inflater.inflate(r.layout.item_pager_image, container, false);         assert imagelayout != null;         touchimageview imageview = (touchimageview) imagelayout.findviewbyid(r.id.image);         final progressbar spinner = (progressbar) imagelayout.findviewbyid(r.id.loading);           imageloader.getinstance().displayimage(images_list.get(position).geturl(), imageview, options, new simpleimageloadinglistener() {             @override             public void onloadingstarted(string imageuri, view view) {                 spinner.setvisibility(view.visible);                  view.setvisibility(view.gone);             }              @override             public void onloadingfailed(string imageuri, view view, failreason failreason) {                 string message = null;                 switch (failreason.gettype()) {                     case io_error:                         message = "input/output error";                         break;                     case decoding_error:                         message = "image can't decoded";                         break;                     case network_denied:                         message = "downloads denied";                         break;                     case out_of_memory:                         message = "out of memory error";                         break;                     case unknown:                         message = "unknown error";                         break;                 }                 toast.maketext(view.getcontext(), message, toast.length_short).show();                  spinner.setvisibility(view.gone);             }              @override             public void onloadingcomplete(string imageuri, view view, bitmap loadedimage) {                 spinner.setvisibility(view.gone);                 view.setvisibility(view.visible);                 log.i("rae", "loading completed");               }         });          container.addview(imagelayout, 0);         return imagelayout;     }      @override     public void destroyitem(viewgroup container, int position, object object) {         container.removeview((view) object);     }      @override     public int getcount() {         return images_list.size();     }       @override     public boolean isviewfromobject(view view, object object) {         return view.equals(object);     }      @override     public void restorestate(parcelable state, classloader loader) {     }      @override     public parcelable savestate() {         return null;     } } 

item_pager_image.xml

    <?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:padding="1dip">      <info.androidhive.slidingmenu.util.touchimageview         android:id="@+id/image"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_gravity="center"         android:adjustviewbounds="true"         android:contentdescription="@string/app_name" />      <progressbar         android:id="@+id/loading"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:visibility="gone" />  </framelayout> 

i met same problem.just call single tap confirmed method & hide or show views on & add pager adapter same file.

code:

  public class imageviewpager extends activity {     // declare variable     int position;     button delete, gimmy, done;     viewpager viewpager;     imagepageradapter pageradapter;     touchimageview imageview;     textview text;     runnable r;     handler mhandler;     relativelayout rel;     gesturedetector gesturedetector;      @suppresslint("newapi")     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         // set title viewpager         setcontentview(r.layout.view_pager);         mhandler=new handler();         delete=(button) findviewbyid(r.id.del);         done=(button) findviewbyid(r.id.done);         gimmy=(button) findviewbyid(r.id.gimmy);         rel=(relativelayout)findviewbyid(r.id.relative);         actionbar bar = getactionbar();         bar.setdisplayhomeasupenabled(true);         bar.sethomebuttonenabled(true);         settitle("viewpager");         intent p = getintent();         position = p.getextras().getint("id");         pageradapter = new imagepageradapter(imageviewpager.this);         viewpager = (viewpager) findviewbyid(r.id.pager);         viewpager.setadapter(pageradapter);         viewpager.setcurrentitem(position);           r=new runnable() {                @override               public void run() {                  // todo auto-generated method stub                  delete.setvisibility(view.gone);                  done.setvisibility(view.gone);                  gimmy.setvisibility(view.gone);              }              };             mhandler.postdelayed(r,5*1000);           done.setonclicklistener(new onclicklistener() {                  @override                 public void onclick(view v) {                      intent p = new intent(getapplicationcontext(), mainactivity.class);                      startactivity(p);                 }             });           gimmy.setonclicklistener(new onclicklistener() {                  @override                 public void onclick(view v) {                  }             });           delete.setonclicklistener(new onclicklistener() {                   @override                 public void onclick(view v) {                      }                 });           viewpager.setonpagechangelistener(new onpagechangelistener() {                   @override                 public void onpageselected (int page)                 {                      delete.setvisibility(view.gone);                      done.setvisibility(view.gone);                      gimmy.setvisibility(view.gone);                 }                  @override                 public void onpagescrolled (int arg0, float arg1, int arg2)                 {                  }                  @override                 public void onpagescrollstatechanged (int arg0)                 {                 }              });       }       @override     public boolean onoptionsitemselected(menuitem item) {         // todo auto-generated method stub          switch (item.getitemid()) {         case android.r.id.home:              finish();             overridependingtransition(r.anim.slide_enter, r.anim.slide_exit);             return true;          default:             return super.onoptionsitemselected(item);          }      }       @override     public boolean onkeydown(int keycode, keyevent event) {         if (keycode == keyevent.keycode_back) {             intent p = new intent(getapplicationcontext(), slideimages.class);             // p.putextra("id", pos+1);             startactivity(p);         }          return super.onkeydown(keycode, event);     }  /**  * adapter class viuew pager.we have used in same file baecause reference lost in file.  * **/     public class imagepageradapter extends pageradapter {         layoutinflater inflater;         photoviewattacher attacher;         private displayimageoptions options;         private  list<wallpaper>  images_list=appcontroller.getinstance().getprefmanger().getallimages();               public imagepageradapter(context context)              {                     inflater = layoutinflater.from(context);                      options = new displayimageoptions.builder()                     .showimageforemptyuri(r.drawable.ic_empty)                     .showimageonfail(r.drawable.ic_error)                     .resetviewbeforeloading(true)                     .cacheondisk(true)                     .imagescaletype(imagescaletype.exactly)                     .bitmapconfig(bitmap.config.rgb_565)                     .considerexifparams(true)                     .displayer(new fadeinbitmapdisplayer(300))                     .build();             }          @override         public object instantiateitem(viewgroup container, int position)         {             view imagelayout = inflater.inflate(r.layout.item_pager_image, container, false);             assert imagelayout != null;             touchimageview imageview = (touchimageview) imagelayout.findviewbyid(r.id.image);             final progressbar spinner = (progressbar) imagelayout.findviewbyid(r.id.loading);             imageview.setondoubletaplistener(new ondoubletaplistener() {                  @override                 public boolean onsingletapconfirmed(motionevent e) {                     // todo auto-generated method stub                     delete.setvisibility(view.visible);                     done.setvisibility(view.visible);                     gimmy.setvisibility(view.visible);                     return false;                 }                  @override                 public boolean ondoubletapevent(motionevent e) {                     // todo auto-generated method stub                     return false;                 }                  @override                 public boolean ondoubletap(motionevent e) {                     // todo auto-generated method stub                     return false;                 }             });              imageloader.getinstance().displayimage(images_list.get(position).geturl(), imageview, options, new simpleimageloadinglistener() {                 @override                 public void onloadingstarted(string imageuri, view view) {                     spinner.setvisibility(view.visible);                      view.setvisibility(view.gone);                 }                  @override                 public void onloadingfailed(string imageuri, view view, failreason failreason) {                     string message = null;                     switch (failreason.gettype()) {                         case io_error:                             message = "input/output error";                             break;                         case decoding_error:                             message = "image can't decoded";                             break;                         case network_denied:                             message = "downloads denied";                             break;                         case out_of_memory:                             message = "out of memory error";                             break;                         case unknown:                             message = "unknown error";                             break;                     }                     toast.maketext(view.getcontext(), message, toast.length_short).show();                      spinner.setvisibility(view.gone);                 }                  @override                 public void onloadingcomplete(string imageuri, view view, bitmap loadedimage) {                     spinner.setvisibility(view.gone);                     view.setvisibility(view.visible);                     log.i("rae", "loading completed");                   }             });              container.addview(imagelayout, 0);             return imagelayout;         }          @override         public void destroyitem(viewgroup container, int position, object object) {             container.removeview((view) object);         }          @override         public int getcount() {             return images_list.size();         }           @override         public boolean isviewfromobject(view view, object object) {             return view.equals(object);         }          @override         public void restorestate(parcelable state, classloader loader) {         }          @override         public parcelable savestate() {             return null;         }     }   } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -