java - Load multiple bitmaps in Android Studio one at time with threads -
i'm working on project takes pictures camera , saves photopath in database, working fine , i'm handling memory correctly generating thumbnails when load images.
the thing want i'm trying dedicate threads go loading images 1 per 1 in layout, because example, if have 50, normal load shows layout until 50 loaded, meanwhile doesn't show anything.
i've tried implement threads load one, , one, it's same, until loads all, shows all, here code:
string query = "select id_reg_mem, information memory_reg type = 'photo' , id_memory =" + id_memory; final cursor resultado = memorydb.rawquery(query, null); if(resultado.movetofirst()) nophotos = resultado.getcount(); for(int i=0; i<nophotos; i++) { new thread() { public void run() { getactivity().runonuithread(new runnable() { @override public void run() { updatenewphoto(resultado.getstring(1)); // send path db method made add tablerow image (inside imageview) } }); } }.start(); if(i + 1 == nophotos) break; resultado.movetonext(); }
here method, i'm loading single image imageview inside tablerow. method working load images db.
protected void updatenewphoto(string path) { imageview iv; if(rows == null) { rows = new arraylist<tablerow>(); rows.add(new tablerow(tl.getcontext())); iv = new imageview(tl.getcontext()); iv.setlayoutparams(new tablerow.layoutparams(250,250)); iv.settag(db_utils.maxidregmem(memorydb) - 1); iv.setimagebitmap(getbitmapthumbnail(path)); rows.get(0).addview(iv); tl.addview(rows.get(0)); count = 2; } else { iv = new imageview(tl.getcontext()); iv.setlayoutparams(new tablerow.layoutparams(250,250)); iv.settag(db_utils.maxidregmem(memorydb) - 1); iv.setimagebitmap(getbitmapthumbnail(path)); if(count == 2) { rows.get(rows.size() - 1).addview(iv); count = 1; } else { rows.add(new tablerow(tl.getcontext())); rows.get(rows.size() - 1).addview(iv); tl.addview(rows.get(rows.size() - 1)); count = 2; } }
unfortunately me, images aren't shown until of them loaded (kind of 3 seconds takes). i'm thinking in no limit of images, that's why want way images loaded 1 per one, not together.
any ideas have? appreciate help. thanks.
Comments
Post a Comment