android - images not appearing in gridView but after keyboard actived -


i have 2 activites,transporting arraylist imageurls activity addproductactivity activity sdcard. sdcard.java code is:

    public class sdcard extends activity {          private arraylist<string> imageurls;         private displayimageoptions options;         private imageadapter imageadapter;         imageloader imageloader;          @suppresswarnings("deprecation")         @override         public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_photoalbum);              getactionbar();             getactionbar().sethomebuttonenabled(true);             getactionbar().setdisplayhomeasupenabled(true);             getactionbar().setdisplayshowtitleenabled(true);             getactionbar().settitle("select image");              final string[] columns = { mediastore.images.media.data,                     mediastore.images.media._id };             final string orderby = mediastore.images.media.date_taken;             cursor imagecursor = managedquery(                     mediastore.images.media.external_content_uri, columns, null,                     null, orderby + " desc");              this.imageurls = new arraylist<string>();              (int = 0; < imagecursor.getcount(); i++) {                 imagecursor.movetoposition(i);                 int datacolumnindex = imagecursor                         .getcolumnindex(mediastore.images.media.data);                 imageurls.add(imagecursor.getstring(datacolumnindex));                  system.out.println("=====> array path => " + imageurls.get(i));             }              options = new displayimageoptions.builder()                     .showimageforemptyuri(r.drawable.ic_launcher)                     .showimageonfail(r.drawable.ic_error_loadingsmall)                     .cacheinmemory(true)                     .cacheondisk(true)                     .considerexifparams(true)                     .bitmapconfig(bitmap.config.rgb_565)                     .build();              imageloader = imageloader.getinstance();             imageloader.init(imageloaderconfiguration.createdefault(this));              imageadapter = new imageadapter(this, imageurls);              gridview gridview = (gridview) findviewbyid(r.id.album_gridview);             gridview.setadapter(imageadapter);         }          @override         public boolean oncreateoptionsmenu(menu menu) {             // inflate menu; adds items action bar if present.             getmenuinflater().inflate(r.menu.select_image, menu);             return true;         }          @override         public boolean onoptionsitemselected(menuitem item) {              switch (item.getitemid()) {             case android.r.id.home:                 intent intent = new intent(sdcard.this, addproductactivity.class);                 intent.addflags(intent.flag_activity_clear_top);                 startactivity(intent);                 return true;             case r.id.select_image_submit:                 arraylist<string> selecteditems = imageadapter.getcheckeditems();                 if (selecteditems.size() == 0) {                     toast.maketext(getbasecontext(), "no selected image!", toast.length_long)                             .show();                 } else if (selecteditems.size() > 9) {                     toast.maketext(getbasecontext(), "must below 9 images", toast.length_long)                             .show();                 } else {                     intent intent1 = new intent(this, addproductactivity.class);                     intent1.putstringarraylistextra("select_image", selecteditems);                     intent1.setflags(intent.flag_activity_clear_top);                     setresult(9392,intent1);                     finish();                 }             default:                 return super.onoptionsitemselected(item);             }         }          @override         protected void onstop() {             imageloader.stop();             super.onstop();         }          public class imageadapter extends baseadapter {              arraylist<string> mlist;             layoutinflater minflater;             context mcontext;             sparsebooleanarray msparsebooleanarray;              public imageadapter(context context, arraylist<string> imagelist) {                 // todo auto-generated constructor stub                 mcontext = context;                 minflater = layoutinflater.from(mcontext);                 msparsebooleanarray = new sparsebooleanarray();                 mlist = new arraylist<string>();                 this.mlist = imagelist;             }              public arraylist<string> getcheckeditems() {                 arraylist<string> mtemparry = new arraylist<string>();                  (int = 0; < mlist.size(); i++) {                     if (msparsebooleanarray.get(i)) {                         mtemparry.add(mlist.get(i));                     }                 }                 return mtemparry;             }              @override             public int getcount() {                 return imageurls.size();             }              @override             public object getitem(int position) {                 return null;             }              @override             public long getitemid(int position) {                 return position;             }              @override             public view getview(final int position, view convertview,                     viewgroup parent) {                 final progressbar spinner = (progressbar) findviewbyid(r.id.loading_image_fromsdcard);                  if (convertview == null) {                     convertview = minflater.inflate(                             r.layout.photoalbum_gridview_item, null);                 }                  checkbox mcheckbox = (checkbox) convertview                         .findviewbyid(r.id.select_image_cb);                  final imageview imageview = (imageview) convertview                         .findviewbyid(r.id.photo_img_view);                  imageloader.displayimage("file://" + imageurls.get(position),                         imageview, options, new simpleimageloadinglistener() {                             @override                             public void onloadingstarted(string imageuri, view view) {                                 spinner.setvisibility(view.visible);                             }                              @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(sdcard.this, message,                                         toast.length_short).show();                                 spinner.setvisibility(view.gone);                             }                              @override                             public void onloadingcomplete(string imageuri,                                     view view, bitmap loadedimage) {                                 spinner.setvisibility(view.gone);                                 animation anim =animationutils.loadanimation(sdcard.this,                                 r.anim.push_left_in);                                 imageview.setanimation(anim);                                 anim.start();                                 }                         });                  imageview.setonclicklistener(new onclicklistener() {                      @override                     public void onclick(view v) {                         // todo auto-generated method stub                         toast.maketext(getbasecontext(),                                 "selected item " + position, toast.length_long)                                 .show();                     }                 });                  mcheckbox.settag(position);                 mcheckbox.setchecked(msparsebooleanarray.get(position));                 mcheckbox.setoncheckedchangelistener(mcheckedchangelistener);                  return convertview;             }              oncheckedchangelistener mcheckedchangelistener = new oncheckedchangelistener() {                  @override                 public void oncheckedchanged(compoundbutton buttonview,                         boolean ischecked) {                     // todo auto-generated method stub                     msparsebooleanarray.put((integer) buttonview.gettag(),                             ischecked);                 }             };         }     } 

and activity addproductactivity recive imageurls activity sdcard , display image on it, code

    public class addproductactivity extends activity{          gridview gridview;         private string image;         private static final int gallery_request = 9390;         private displayimageoptions options;         imageloader imageloader;         private arraylist<string> selectimageurls;         string[] f;         private selectimageadapter selectimageadapter;         imageview imageview;          @suppresswarnings("deprecation")         @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_add_product);              final actionbar actionbar = getactionbar();             actionbar.setdisplayshowtitleenabled(false);             // actionbar.setnavigationmode(actionbar.navigation_mode_list);             actionbar.sethomebuttonenabled(true);             actionbar.setdisplayhomeasupenabled(true);             actionbar.setdisplayshowtitleenabled(true);             actionbar.settitle("add product");              options = new displayimageoptions.builder()                     .showstubimage(r.drawable.ic_launcher)                     .showimageonfail(r.drawable.ic_error_loadingsmall)                     .cacheinmemory().cacheondisc().build();              gridview = (gridview) findviewbyid(r.id.select_image_gridview);             this.selectimageurls = new arraylist<string>();          }          @override         public boolean oncreateoptionsmenu(menu menu) {              // inflate menu; adds items action bar if present.             getmenuinflater().inflate(r.menu.add_product, menu);             return true;         }          @override         public boolean onoptionsitemselected(menuitem item) {                    switch (item.getitemid()) {             case android.r.id.home:                 intent intent = new intent(addproductactivity.this,                         mainactivity.class);                 intent.addflags(intent.flag_activity_clear_top);                 startactivity(intent);                 return true;             case r.id.action_upload_picture:                 return true;             default:                 return super.onoptionsitemselected(item);             }         }         public void onselectfromsd(menuitem item) {              intent selectfromsdcard = new intent(addproductactivity.this,sdcard.class);             startactivityforresult(selectfromsdcard, gallery_request);          }          @override         public void onactivityresult(int requestcode, int resultcode, intent data) {             system.out.println("[requestcode=" + requestcode + "]" + "[resultcode="                     + resultcode + "]");              if (requestcode == gallery_request && resultcode == 9392                     && data != null) {                  // image = data.getdata().tostring();                 selectimageurls = data.getstringarraylistextra("select_image");                              if (selectimageurls != null) {                     // system.out.println("recieve =" + selectimageurls.size());                     f = (string[]) selectimageurls                             .toarray(new string[selectimageurls.size()]);                     if (selectimageadapter == null) {                                                selectimageadapter = new selectimageadapter(this,                                 selectimageurls);                          imageloader.init(imageloaderconfiguration                                 .createdefault(this));                         gridview.setadapter(selectimageadapter);                         selectimageadapter.notifydatasetchanged();                         gridview.setonitemclicklistener(new onitemclicklistener() {                              @override                             public void onitemclick(adapterview<?> parent,                                     view view, int position, long id) {                                  startfullimagepageractivity(position);                              }                         });                      } else {                          selectimageadapter.notifydatasetchanged();                     }                  } else {                     return;                 }              } else {                 super.onactivityresult(requestcode, resultcode, data);             }         }          protected void startfullimagepageractivity(int position) {             // todo auto-generated method stub             intent = new intent(addproductactivity.this,                     fullscreenviewactivity.class);             i.putstringarraylistextra("position_url", selectimageurls);             i.putextra("position", position);             startactivity(i);         }          public class selectimageadapter extends baseadapter {              layoutinflater minflater;             context mcontext;              public selectimageadapter(context context, arraylist<string> imagelist) {                 // todo auto-generated constructor stub                 mcontext = context;                 minflater = layoutinflater.from(mcontext);                 imageloader = imageloader.getinstance();             }              @override             public int getcount() {                 // todo auto-generated method stub                 return selectimageurls.size();             }              @override             public object getitem(int position) {                 // todo auto-generated method stub                 return null;             }              @override             public long getitemid(int position) {                 // todo auto-generated method stub                  return position;             }                  @override         public view getview(int position, view convertview, viewgroup parent) {             // todo auto-generated method stub             if (convertview == null) {                 convertview = minflater.inflate(r.layout.select_image, null);             }             final imageview imageview = (imageview) convertview.findviewbyid(r.id.select_images);             final progressbar spinner = (progressbar)convertview.findviewbyid(r.id.select_image_loading);              //final viewanimator animator = (viewanimator)convertview.findviewbyid(r.id.animator);             imageloader.displayimage("file://" + selectimageurls.get(position), imageview,                     options, new simpleimageloadinglistener() {                         @override                         public void onloadingstarted(string imageuri, view view) {                             spinner.setvisibility(view.visible);                             //animator.setdisplayedchild(1);                         }                          @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(addproductactivity.this, message,toast.length_short).show();                             spinner.setvisibility(view.gone);                             //animator.setdisplayedchild(0);                         }                          @override                         public void onloadingcomplete(string imageuri,                                 view view, bitmap loadedimage) {                             // animation anim =                             // animationutils.loadanimation(sdcard.this,                             // r.anim.push_left_in);                             // imageview.setanimation(anim);                             // anim.start();                             spinner.setvisibility(view.gone);    notifydatasetchanged();//followed armin's suggestion                     }                     });             return convertview;         }     } 

but when returned activity addproductactivity,the images did not appear in gridview ,if clicked editortext active keyboard,the images appearing in gridview. puzzled,waiting suggestions, thanks!

image url :http://i61.tinypic.com/2ch9onq.png actived keyboard image appearing: http://i61.tinypic.com/2l8uumc.png

if used getview() method in addproductactivity,it works fine.

@override          public view getview(final int position, view convertview, viewgroup          parent)          {                if (convertview == null){              imageview = new imageview(mcontext);              imageview.setlayoutparams(new gridview.layoutparams(245, 150));              imageview.setscaletype(imageview.scaletype.center_crop);          }          else {              imageview = (imageview) convertview;          }                 bitmapfactory.options bmoptions = new bitmapfactory.options();                 bmoptions.injustdecodebounds = false ;                 bmoptions.insamplesize = 4;                 bmoptions.inpurgeable = true ;                 bitmap bitmap = bitmapfactory.decodefile(selectimageurls.get(position), bmoptions);                 imageview.setimagebitmap(bitmap);                  return imageview;          } 

but not smooth when transfored imageurls addproductactivity.

try replace adapter code.

  public class selectimageadapter extends baseadapter {          context mcontext;         viewholder holder;          public selectimageadapter(context context, arraylist<string> imagelist) {             // todo auto-generated constructor stub             mcontext = context;             imageloader = imageloader.getinstance();         }          @override         public int getcount() {             // todo auto-generated method stub             return selectimageurls.size();         }          @override         public object getitem(int position) {             // todo auto-generated method stub             return null;         }          @override         public long getitemid(int position) {             // todo auto-generated method stub              return position;         }          @override         public view getview(int position, view convertview, viewgroup parent) {             if (convertview == null) {                 holder = new viewholder();                 convertview = layoutinflater.from(mcontext).inflate(r.layout.select_image, null);                 holder.imageview =  (imageview) convertview.findviewbyid(r.id.select_images);                 holder.spinner = (progressbar)convertview.findviewbyid(r.id.select_image_loading);                 convertview.settag(holder);             }else{                 holder = (viewholder) convertview.gettag();             }              //final viewanimator animator = (viewanimator)convertview.findviewbyid(r.id.animator);             imageloader.displayimage("file://" + selectimageurls.get(position),holder.imageview,                     options, new simpleimageloadinglistener() {                         @override                         public void onloadingstarted(string imageuri, view view) {                             holder.spinner.setvisibility(view.visible);                             //animator.setdisplayedchild(1);                         }                          @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(addproductactivity.this, message,toast.length_short).show();                             holder.spinner.setvisibility(view.gone);                             //animator.setdisplayedchild(0);                         }                          @override                         public void onloadingcomplete(string imageuri,                                                       view view, bitmap loadedimage) {                             // animation anim =                             // animationutils.loadanimation(sdcard.this,                             // r.anim.push_left_in);                             // imageview.setanimation(anim);                             // anim.start();                             holder.spinner.setvisibility(view.gone);                         }                     });              return convertview;         }          class viewholder {             imageview imageview;             progressbar spinner;         }      } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -