android - ProgressBar is not set visible before other operations by click button -
i work mediaplayer
, want show progressbar
before calling method mediaplayer.prepare()
(it can take time). tried asynktast, thread, handler
show progressbar after operations @ end of clickplaybutton
method. wrong? thanks!
progressbar declaration:
<progressbar android:id="@+id/progressbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="invisible"/>
clickplaybutton method
public void clickplaybutton(view view) { thread t = new thread(new runnable() { public void run() { h.post(updateprogress); } }); t.start(); // progressbar.setvisibility(progressbar.visible); // new progresstask().execute(); mtimer = new timer(); mmytimertask = new mytimertask(); if(!mediaplayer.isplaying()){ btnplay.setimageresource(r.drawable.player_stop); try { mediaplayer.setdatasource(data_http); mediaplayer.prepare(); } catch (exception e) { e.printstacktrace(); } mediaplayer.start(); mtimer.schedule(mmytimertask, 10, 5000); } else { btnplay.setimageresource(r.drawable.player_play); mediaplayer.pause(); mtimer.cancel(); } // progressbar.setvisibility(progressbar.invisible); } handler h = new handler(); runnable updateprogress = new runnable() { public void run() { progressbar.setvisibility(view.visible); } };
wiki
Comments
Post a Comment