android - How to transform basic code into more efficient AQuery code -


my questions delay image loading using aquery

so app : read json, contains various information, , links images(this done in procedure doinbackground asynctask). also, after reading links in procedure, read pics (see code below more info)

 class getmessages extends asynctask<string, void, string> {       @override protected string doinbackground(string... params) {     httpclient httpclient = new defaulthttpclient();     httpget httpget = new httpget(uri);              // code reads json .......     bitmap picture = null;     try {       url newurl = new url(json.getstring("pic_url"));       picture = bitmapfactory.decodestream(newurl.openconnection() .getinputstream());     }catch (ioexception e) {       // todo auto-generated catch block       e.printstacktrace();     }              // after this, put read info, , pics in list of              // objects, usen in method onpostexecute populate             //  custom adapter ...see code below   static class viewholder { imageview picview;  }  public class mycustombaseadapter extends baseadapter  {      private layoutinflater minflater;      private arraylist<product> products;      public arraylist<product> getproducts() {         return products;     }      public void setproducts(arraylist<product> products) {         this.products = products;     }      public mycustombaseadapter(context context, arraylist<product> products) {          this.products = products;          this.minflater = layoutinflater.from(context);      }       public int getcount() {          return products.size();      }       public object getitem(int position) {          return products.get(position);      }       public long getitemid(int position) {          return position;      }       public view getview(int position, view convertview, viewgroup parent) {           viewholder holder;           if (convertview == null) {              convertview = minflater.inflate(r.layout.product_item, null);              holder = new viewholder();              holder.picview = (imageview) convertview.findviewbyid(r.id.pic_view);               convertview.settag(holder);           } else {              holder = (viewholder) convertview.gettag();          }            holder.picview.setimagebitmap(products.get(position).getpicture());             return convertview;      } 

as can figure out...if have 15 pics...the users gets sleepy before information loaded...

  1. what want do, use delay image loading...however, can't seem put pieces together...how should modify adapter?
  2. do add code wiki page, , use instead of method view ? ...any or link more complete example on wiki, beginner me :)
  3. can framework used in commercial app too?

thanks :)

here's source of demo use shoulddelay:

https://github.com/androidquery/androidquery/blob/master/demo/src/com/androidquery/test/image/imageloadinglistactivity.java https://github.com/androidquery/androidquery/blob/master/demo/src/com/androidquery/test/image/imageloadinglist4activity.java

try 1 step @ time.

i suggest replace few lines in getview method in example , use aq.image load images urls.

replace:

holder.picview.setimagebitmap(products.get(position).getpicture());  with:  aquery aq = new aquery(convertview); aq.id(holder.picview).image(products.get(position).getpicture()); 

after add shoulddelay make more efficient.

the answer belongs peter liu, 1 of gurus concerning framework :)


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -