android - ImageView visibility Error with Timer -
package name.cpr; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import java.util.timer; import java.util.timertask; public class exampleactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_example); timer timer = new timer(); timer.schedule(new checkconnection(), 0, 3000); imageview iv = (imageview) findviewbyid(r.id.imageview); iv.setvisibility(view.visible); } class checkconnection extends timertask{ public void run(){ imageview iv = (imageview) findviewbyid(r.id.imageview); iv.setvisibility(view.invisible); //<- unfortunatly error here } } }
starting app, first time image view visibility work timer not working, if timer started same error unfortunately .... has stopped
you may want use android.os.handler instead.
public class exampleactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_example); imageview iv = (imageview) findviewbyid(r.id.imageview); iv.setvisibility(view.visible); // new handler().postdelayed(new runnable() { @override public void run() { iv.setvisibility(view.invisible); } }, 3000); } }
good luck. :)
Comments
Post a Comment