android - How to make a image visible after completion of Thread? -
i making project in using progressdialog , want show progress dialog on creation of activity , able that. in on create method want image invisible , want image visible after completion of progress dialog throwing exception in line imagevisible();
the logcat is:
04-12 12:48:35.309: e/androidruntime(4994): @ com.example.project1.showpassword$waiter.run(showpassword.java:59)
code
imageview iv; progressdialog p; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.showpass); iv=(imageview)findviewbyid(r.id.imageview1); iv.setvisibility(view.invisible); p= new progressdialog(this); p.setprogressstyle(progressdialog.style_horizontal); p.settitle("getting password: "); p.setmessage("loading:"); p.setmax(100); p.show(); thread t=new thread(new waiter()); t.start(); public class waiter extends thread{ public void run(){ for(int i=0; i<5; i++){ p.incrementprogressby(20); try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } }p.dismiss(); imagevisible(); } } public void imagevisible(){ iv.setvisibility(view.visible); }
you can't change ui non ui thread. can use runonuithread
method of activity
:
public class waiter extends thread{ public void run(){ //... runonuithread(new runnable() { @override public void run() { imagevisible(); } }); } }
Comments
Post a Comment