i have multiple images , uploading on php server using asynctask problem want show circular progress bar on every image individually whatsapp don't know how do. here code
/** * uploading file server * */ private class uploadfiletoserver extends asynctask<void, integer, string> { @override protected void onpreexecute() { super.onpreexecute(); } @override protected void onprogressupdate(integer... progress) { } @override protected string doinbackground(void... params) { return uploadfile(); } @suppresswarnings("deprecation") private string uploadfile() { string responsestring = null; httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(serviceurl+"conversations.php"); try { multipartentitybuilder entity = multipartentitybuilder.create(); /* example setting httpmultipartmode */ entity.setmode(httpmultipartmode.browser_compatible); file sourcefile = new file(imgdecodablestring); // progress listener - updates task's progress myhttpentity.progresslistener progresslistener = new myhttpentity.progresslistener() { @override public void transferred(float progress) { publishprogress((int) progress); } }; // adding file data http body entity.addpart("file", new filebody(sourcefile)); // parameters if want pass server entity.addtextbody("from_user",(prefid.getstring("userid", null)),contenttype.text_plain); entity.addtextbody("to_user",touser_id,contenttype.text_plain); entity.addtextbody("message_type", msg_type,contenttype.text_plain); httppost.setentity(new myhttpentity(entity.build(), progresslistener)); // making server call httpresponse response = httpclient.execute(httppost); httpentity r_entity = response.getentity(); int statuscode = response.getstatusline().getstatuscode(); if (statuscode == 200) { responsestring = entityutils.tostring(r_entity); } else { responsestring = "error occurred! http status code: " + statuscode; } } catch (clientprotocolexception e) { responsestring = e.tostring(); } catch (ioexception e) { responsestring = e.tostring(); } return responsestring; } @override protected void onpostexecute(string result) { super.onpostexecute(result); } }
i calling above code in main activity , using upload images , video.
please me how can set progress bar on multiple images same in whatsapp
thanks
you pass view asynctask, create new constructor show/hide it, notice have runonuithread view.
private class uploadfiletoserver extends asynctask<void, integer, string> { imageview iv_loading; public uploadfiletoserver(imageview iv_loading){ this.iv_loading = iv_loading; } @override protected void onpreexecute() { super.onpreexecute(); runonuithread(new runnable() { @override public void run() { iv_loading.setvisibility(view.visible); } } ); } ... @override protected void onpostexecute(string result) { super.onpostexecute(result); runonuithread(new runnable() { @override public void run() { iv_loading.setvisibility(view.gone); } } ); } }
Comments
Post a Comment