android - Refresh an imageview in a listview, on click listener -


i have custom listview layout contains imageview , 2 buttons; set primary , rotate image.

what expect behave when user clicked set primary, set primary button invisible. rotate button, refresh imageview rotating 0, 90, 180, 270 degrees.

all of these processes being done server. so, have request web service , response change state of ui.

here listview adapter:

@override public view getview(int i, view view, viewgroup viewgroup) {     ...      itemimagemodel iim = items.get(i);      if (iim.getprimary().equals("0")){         vh.btnprimary.setvisibility(view.visible);     } else {         vh.btnprimary.setvisibility(view.invisible);     }      vh.btnrotate.setvisibility(view.visible);      picasso.with(context) //             .load(iim.getimage50()) //             .placeholder(r.drawable.placeholder) //             .error(r.drawable.error)             .into(vh.ivphoto);      vh.btnprimary.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             log.d(this.getclass().getsimplename(), "set primary");          //  setasprimary();         }     });      vh.btnrotate.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             log.d(this.getclass().getsimplename(), "rotate");         //  rotateimage();         }     });      return view; } 

json response after successful primary image set:

{   "results": "successfully set primary image",   "errors": "" } 

json response after successful image rotation. degree sent via post parameter:

{   "results": "successfully set rotate image",   "errors": "" } 

how refresh listview updated ui according new json response? need refresh listfragment uses adapter? if please let me know.

you'll make http asynchronous call inside of onclicklistener. http call should have return callback fired once there response server. in callback, can update ui accordingly. works if have httpclient set nicely callbacks. if don't have one, i'd check out retrofit.

here's little example pseudocode:

 vh.btnprimary.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view view) {         log.d(this.getclass().getsimplename(), "set primary");         myhttpclient.post(url url, mydetails details, new mycallback() {              private void onsuccess(jsonbody body) {                 updateuiprimary();             }              private void onfailure(jsonbody body) {                 failedapicall();             }         }     } });  vh.btnrotate.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view view) {         log.d(this.getclass().getsimplename(), "rotate");         myhttpclient.post(url url, int rotation, new mycallback() {              private void onsuccess(jsonbody body) {                 updateuirotated();             }              private void onfailure(jsonbody body) {                 failedapicall();             }         }             } }); 

i'm not sure how make post calls, or how post parameters server, put in dummy arguments url, details, body, etc. differ based on how implement http calls


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -