android - Changing ProgressBar visibility from inside onClick -
my activity_main.xml contains progressbar, starts hidden ("gone")
<progressbar android:id="@+id/progressbar_sendingphonenumber" style="?android:attr/progressbarstylelarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button_sendphonenumber" android:layout_centerinparent="true" android:visibility="gone" />
and mainactivity.java has this,
onclick handler button have
final context context = this; sendphonenumberbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { progressbar progressbar = (progressbar) findviewbyid(r.id.progressbar_sendingphonenumber); progressbar.setvisibility(view.visible); // simulate http connection try { thread.sleep(3000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } progressbar.setvisibility(view.gone); // redirect new activity intent intent = new intent(context, inboxactivity.class); startactivity(intent); } });
the problem progress bar never shown, although onclick code executed (eg. redirected new activity @ end). line:
progressbar.setvisibility(view.visible);
isn't taking effect.
i think has context, , trying change visibility of progressbar "outside" activity, i'm not sure.
how can solve this?
it never shown because calling
try { thread.sleep(3000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); }
that makes "sleep" thread responsible draw same progressbar
trying show
Comments
Post a Comment