android - can't show image after use function runnable -


i have problem error on code,

public class mainactivity2 extends activity {  edittext et; imageview iv; runnable stream; handler hand = new handler();     runnable run ;     public button tombol2; @suppresslint("newapi") @override  public void oncreate(bundle savedinstancestate) {  super.oncreate(savedinstancestate);  setcontentview(r.layout.activity_main2);  intent intent = getintent();      string url= intent.getstringextra("url"); tombol2 = (button) findviewbyid(r.id.button2);  iv = (imageview) findviewbyid(r.id.imageview1); drawable d1=loadimagefromweboperations(url); iv.setimagedrawable(d1);     handler handler = new handler();      handler.postdelayed(new runnable() {      @override public void run() {         // todo auto-generated method stub         iv.setimagedrawable(d1);         }     }, 10000); }     private drawable loadimagefromweboperations(string url) {      try      {          inputstream = (inputstream) new url(url).getcontent();          drawable d = drawable.createfromstream(is, "src name");          return d;      }catch (exception e) {          system.out.println("exc="+e);          return null;      }   } 

}

i can't see image in application after use runnable , handler function, have error on side void run, iv.setimagedrawable(d1); how fix ? display , runnable image

first, function drawable should this:

private drawable loadimagefromweboperations(string url) {     drawable drawable = null;      try {         inputstream inputstream = new url(url).openstream();         drawable = drawable.createfromstream(inputstream, null);         inputstream.close();     }     catch(exception ex) {         system.out.println("exc=" + e);         return null;     }      return drawable; } 

now don't understand use of handler... if want image appear after 10 seconds of activity creation, use this:

final handler handler = new handler(); handler.postdelayed(new runnable() {     @override     public void run() {         imageview iv = (imageview) mainactivity2.this.findviewbyid(r.id.imageview1);         drawable d1 = loadimagefromweboperations(url);         iv.setimagedrawable(d1);     } }, 10000); 

if not use post() instead of postdelayed().


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -