android - Refreshing RecyclerView in a Fragment -


in fragment have refresh() method loads recyclerview in particular fragment after fetching data server using asyncdataclass extends asynctask. , in recycleview adapter using contextmenu calling test function of fragment responsible executing asyncdeleteclass extends asynctask deletes particular item remote server database. problem calling refresh() method in postexecute method of asyncdeleteclass gets delete confirmation.but recyclerview not refreshing if particular item deleted.

oncreateview , reshdisplay() :

public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     /* allow activity show indeterminate progress-bar */      view = inflater.inflate(r.layout.user_plcaes_card_list,container,false);        ctx=inflater.getcontext();      //get calling activity call function     mainactivity activity = (mainactivity) getactivity();     user_id = activity.getuserid();    // toast.maketext(activity,user_id,toast.length_long).show();      refreshdisplay();     return view; }  private void refreshdisplay(){     reclist = (recyclerview) view.findviewbyid(r.id.cardlist);     reclist.sethasfixedsize(true);     linearlayoutmanager llm = new linearlayoutmanager(ctx);     llm.setorientation(linearlayoutmanager.vertical);     reclist.setlayoutmanager(llm);     asyncdataclass asyncrequestobject = new asyncdataclass();     asyncrequestobject.execute(serverurl); } 

test() method responsible deleting , refreshing recyclerview

public void test(string dpid){     deletepid = dpid;     asyncdeleteclass asyncdeleterequestobject = new asyncdeleteclass();     asyncdeleterequestobject.execute(deleteserverurl); } 

asyncdeleteclass:

private class asyncdeleteclass extends asynctask<string, void, string> {          @override          protected string doinbackground(string... params) {              string responsebody = "";              httpparams httpparameters = new basichttpparams();             httpconnectionparams.setconnectiontimeout(httpparameters, 5000);             httpconnectionparams.setsotimeout(httpparameters, 5000);             httpclient httpclient = new defaulthttpclient(httpparameters);             httppost httppost = new httppost(params[0]);             string jsonresult = "";             try {                  httpresponse response = httpclient.execute(httppost);                 jsonresult = inputstreamtostring(response.getentity().getcontent()).tostring();                 system.out.println("returned json object " + jsonresult.tostring());             } catch (clientprotocolexception e) {                  e.printstacktrace();             } catch (ioexception e) {                 e.printstacktrace();             }             return jsonresult;         }          @override         protected void onpreexecute() {             super.onpreexecute();             log.i("async : ","pre exec");             pdialog = new progressdialog(ctx);             pdialog.setmessage("please wait...");             pdialog.setcancelable(true);             pdialog.show();         }          @override          protected void onpostexecute(string result) {              super.onpostexecute(result);             system.out.println("resulted value: " + result);             if(result.equals("") || result == null){                 toast.maketext(ctx, "server connection failed", toast.length_long).show();              }             int jsonresult = returnparsedjsonobject(result);             if(jsonresult == -1){                 toast.maketext(ctx, "sorry unable delete", toast.length_long).show();              }             if(jsonresult == 1){                  toast.maketext(ctx, "place deleted successfully", toast.length_long).show();                 refreshdisplay();             }             if (pdialog.isshowing())                 pdialog.dismiss();         }          private stringbuilder inputstreamtostring(inputstream is) {             string rline = "";             stringbuilder answer = new stringbuilder();             bufferedreader br = new bufferedreader(new inputstreamreader(is));             try {                 while ((rline = br.readline()) != null) {                     answer.append(rline);                 }             } catch (ioexception e) { // todo auto-generated catch block                 e.printstacktrace();             }             return answer;         }     } 

asyncdataclass:

    private class asyncdataclass extends asynctask<string, void, string> {          @override          protected string doinbackground(string... params) {              string responsebody = "";              httpparams httpparameters = new basichttpparams();             httpconnectionparams.setconnectiontimeout(httpparameters, 5000);             httpconnectionparams.setsotimeout(httpparameters, 5000);             httpclient httpclient = new defaulthttpclient(httpparameters);             httppost httppost = new httppost(params[0]);             string jsonresult = "";             try {                  httpresponse response = httpclient.execute(httppost);                 jsonresult = inputstreamtostring(response.getentity().getcontent()).tostring();                 system.out.println("returned json object " + jsonresult.tostring());             } catch (clientprotocolexception e) {                  e.printstacktrace();             } catch (ioexception e) {                 e.printstacktrace();             }             return jsonresult;         }          @override         protected void onpreexecute() {             super.onpreexecute();             log.i("async : ","pre exec");             pdialog = new progressdialog(ctx);             pdialog.setmessage("please wait...");             pdialog.setcancelable(true);             pdialog.show();         }          @override          protected void onpostexecute(string result) {              super.onpostexecute(result);             system.out.println("resulted value: " + result);             if(result.equals("") || result == null){                 toast.maketext(ctx, "server connection failed", toast.length_long).show();              }             int jsonresult = returnparsedjsonobject(result);             if(jsonresult == -1){                 toast.maketext(ctx, "sorry no places found", toast.length_long).show();              }             if(jsonresult == 1){                 //toast.maketext(ctx, "", toast.length_long).show();                 try {                     jsonobject jsonobj = new jsonobject(result);                     // getting json array node                     places = jsonobj.getjsonarray("result");                     // looping through contacts                     (int = 0; < places.length(); i++) {                         jsonobject place = places.getjsonobject(i); //                        string slot = c.getstring(tag_slot); //                        serverreturn.add(slot);                           userplaces placefroserver = new userplaces();                           placefroserver.setid(place.getstring(tag_pid));                           placefroserver.setname(place.getstring(tag_pname));                           placefroserver.setdescription(place.getstring(tag_desc));                           placefroserver.setimg(place.getstring(tag_img));                           placefroserver.setlat(place.getstring(tag_lat));                           placefroserver.setlng(place.getstring(tag_lng));                           placeslist.add(placefroserver);                      }                      places_adapter = new placerscardadapter(placeslist,ctx, checkplacesfragment.this);                     reclist.setadapter(places_adapter);                   } catch (jsonexception e) {                      string ex = e.getmessage();                     e.printstacktrace();                 }              }             if (pdialog.isshowing())                 pdialog.dismiss();         }          private stringbuilder inputstreamtostring(inputstream is) {             string rline = "";             stringbuilder answer = new stringbuilder();             bufferedreader br = new bufferedreader(new inputstreamreader(is));             try {                 while ((rline = br.readline()) != null) {                     answer.append(rline);                 }             } catch (ioexception e) { // todo auto-generated catch block                 e.printstacktrace();             }             return answer;         }     } 


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -