android - I want a progressbar but get a spinner progressdialog -
i using public asyntask download data, , trying show progress bar show download progress. think have code right, spinner progressdialog. missing something? why isn't progress bar showing up? here code. pointers.
public class filedownloader extends asynctask<string, integer, void> { private context _appcontext; private httpurlconnection _urlconn; private progressdialog _progressdia = null; private dialoginterface.oncancellistener _progdiacancellistener = new dialoginterface.oncancellistener() { /** * when progress dialog canceled, stop request. */ public void oncancel(dialoginterface dialog) { filedownloader.this.cancel(true); } }; /** * constructor. * @param appcontext */ public filedownloader(context appcontext) { _appcontext = appcontext; _progressdia = new progressdialog(_appcontext, progressdialog.style_horizontal); _progressdia.setmax(100); _progressdia.settitle(_appcontext.getstring(r.string.diaheader1)); _progressdia.setmessage(_appcontext.getstring(r.string.diabody1)); _progressdia.setcancelable(true); _progressdia.setindeterminate(false); _progressdia.setoncancellistener(_progdiacancellistener); } // runs on ui thread @override protected void onpreexecute() { _progressdia.setprogress(0); _progressdia.show(); } @override protected void doinbackground(string... args) { string dloadurl = args[0], saveloc = args[1]; ... ... while((len = input.read(buf)) > 0) { output.write(buf, 0, len); total += len; publishprogress((int)total * 100/lenghtoffile); } ... ... } catch(sockettimeoutexception ex) { } { ... } // executed on main ui thread. @override protected void onprogressupdate(integer... values) { _progressdia.setprogress(values[0]); } @override protected void oncancelled() { ... } // executed on main ui thread. @override protected void onpostexecute(void result) { removeprogressdialog(); ... } /** * remove message dialog, if still showing. */ private void removeprogressdialog() { if(_progressdia != null && _progressdia.isshowing()) _progressdia.dismiss(); } }
probably forget set dialog.setprogressstyle(progressdialog.style_horizontal);
see example code works me:
progressdialog dialog; @override protected void onpreexecute() { dialog = new progressdialog(this); dialog.setmessage("matching progress"); dialog.setprogressstyle(progressdialog.style_horizontal); dialog.setmax(100); dialog.setcancelable(false); dialog.show(); } /* * (non-javadoc) * @see android.os.asynctask#doinbackground(params[]) */ @override protected void doinbackground(void... params) { return null; } protected void onpostexecute(void result) { dialog.hide(); dialog = null; }
Comments
Post a Comment