Thursday, 15 May 2014

Android ProgressDialog in AsyncTask -



Android ProgressDialog in AsyncTask -

i can't create progressdialog run in asynctask :

private class upload extends asynctask<string, void, void> { progressdialog pd; protected void onpreexecute() { super.onpreexecute(); pd = new progressdialog(activity.this); pd.setmessage("message"); pd.setindeterminate(false); pd.setmax(100); pd.setprogressstyle(progressdialog.style_horizontal); pd.setcancelable(false); pd.show(); } @override protected void doinbackground(string... params) { ....... public void write(byte[] bts, int st, int end) throws ioexception { totalsent += end; progress = (int) ((totalsent / (float) contentlength) * 100); publishprogress("loaded "+progress+"%"); out.write(bts, st, end); } ....... } protected void onprogressupdate(string... progress) { log.d("andro_async", progress[0]); pd.setprogress(integer.parseint(progress[0])); } protected void onpostexecute(void result) { super.onpostexecute(result); if (pd != null) { pd.dismiss(); } }

progress dialog works, no progress on it. in logs see, progress counts properly. so, no problems in progress count.

for code above error, saying "the method publishprogress(void...) in type asynctask string,void,void not applicable arguments (string)".

it doesn't work no matter do. suppose, miss something. please help )

you trying parseint on string containing "loaded "+progress+"%". can't work. seek :

publishprogress(""+progress); // [...] protected void onprogressupdate(string... progress) { log.d("andro_async", "loaded " + progress[0] + "%"); pd.setprogress(integer.parseint(progress[0])); }

android android-asynctask progressdialog

No comments:

Post a Comment