In android the first fragment is not working properly -


i have 2 fragments, first fragment calling methods app starts , second fragment's visibility off when user focusing on second fragment methods of second fragment getting called. if user comes first fragment , there change in data in first fragment, methods first fragment not called , hence change not reflected. how solve problem?

the 2 fragments code are:`

public class tab1fragment extends fragment { private static final string tag = "tab1fragment"; context c; string user_name,password; materialsearchview materialsearchview; string url = null;  recyclerview rv1; tablelayout tablayout;   @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {      view view = inflater.inflate(r.layout.tab1_fragment,container,false);      tablayout=(tablelayout) view.findviewbyid(r.id.tablelayout);     final tablelayout tablayout1=(tablelayout)view.findviewbyid(r.id.tablelayout1);     final tablelayout tablayout2=(tablelayout)view.findviewbyid(r.id.tablelayout2);      materialsearchview = (materialsearchview)getactivity().findviewbyid(r.id.search_view);      sharedpreferences sharedpreferences=this.getactivity().getsharedpreferences("postman", context.mode_private);     user_name=sharedpreferences.getstring("username","nothing");     password=sharedpreferences.getstring("password","nothing");      rv1 = (recyclerview) view.findviewbyid(r.id.mrecycler1);         rv1.setlayoutmanager(new linearlayoutmanager(c));     rv1.setitemanimator(new defaultitemanimator());      download2 d2 = new download2(getactivity(),url,rv1,user_name,password,tablayout,materialsearchview);        d2.execute();       return view; } } 

the other fragment code :

public class tab3fragment extends fragment { private static final string tag = "tab3fragment";  string user_name,password; context c; materialsearchview materialsearchview3; recyclerview rv, rv1; tablelayout tablayout1 , tablayout;   @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {     setuservisiblehint(false);     view view = inflater.inflate(r.layout.tab3_fragment,container,false);       tablayout1=(tablelayout)view.findviewbyid(r.id.tablelayout1);       materialsearchview3 = (materialsearchview)getactivity().findviewbyid(r.id.search_view);      sharedpreferences sharedpreferences=this.getactivity().getsharedpreferences("postman", context.mode_private);     user_name=sharedpreferences.getstring("username","nothing");     password=sharedpreferences.getstring("password","nothing");      rv = (recyclerview) view.findviewbyid(r.id.mrecycler);       rv.setlayoutmanager(new linearlayoutmanager(c));     rv.setitemanimator(new defaultitemanimator());       return view; }  @override public void setmenuvisibility(boolean menuvisible) {     super.setmenuvisibility(menuvisible);     if(menuvisible)     {         download3 d3 = new download3(getactivity(),url,rv,user_name,password,tablayout1, materialsearchview3);         d3.execute();     }    }  }   public class download2 extends asynctask<void,integer,string> {     context c;     recyclerview rv;     progressdialog pd;     string user_name,password;     materialsearchview materialsearchview;       public download2(context c, string url, recyclerview rv, string user_name, string password, tablelayout tablayout, materialsearchview materialsearchview)     {         this.c=c;         this.rv=rv;         this.user_name=user_name;         this.password=password;         this.materialsearchview=materialsearchview;     }        @override     protected string doinbackground(void... params) {         string data=this.downloaddata();         return data;     }      @override     protected  void onpostexecute(final string data)     {         super.onpostexecute(data);          if(data!=null)         {              materialsearchview.setonsearchviewlistener(new materialsearchview.searchviewlistener() {                 @override                 public void onsearchviewshown() {                  }                  @override                 public void onsearchviewclosed() {                      parser p=new parser(c,data,rv);                     p.execute();                 }             });              materialsearchview.setonquerytextlistener(new materialsearchview.onquerytextlistener() {              @override             public boolean onquerytextsubmit(string query) {                 return false;             }              @override             public boolean onquerytextchange(string newtext) {                  toast.maketext(c, "in down2 "+newtext, toast.length_long).show();                      if(newtext!=null && !newtext.isempty())                     {                         parserfilter pf = new parserfilter(c,data,rv,newtext);                         pf.execute();                     }                     else                     {                          parser p=new parser(c,data,rv);                         p.execute();                     }                     return true;                  }             });          }         else         {             toast.maketext(c, "unable download", toast.length_short).show();         }          parser p=new parser(c,data,rv);         p.execute();     }      private string downloaddata()     {         inputstream is=null;         string line=null;            try{              ngroklinks lnk=new ngroklinks();              url url2 = new url(lnk.players());             httpurlconnection httpurlconnection = (httpurlconnection) url2.openconnection();             httpurlconnection.setrequestmethod("post");             httpurlconnection.setdooutput(true);             httpurlconnection.setdoinput(true);             outputstream outputstream = httpurlconnection.getoutputstream();             bufferedwriter bufferedwriter = new bufferedwriter(new outputstreamwriter(outputstream, "utf-8"));             string post_data = urlencoder.encode("user_name", "utf-8") + "=" + urlencoder.encode(user_name, "utf-8") + "&"                     + urlencoder.encode("password", "utf-8") + "=" + urlencoder.encode(password, "utf-8");             bufferedwriter.write(post_data);             bufferedwriter.flush();             bufferedwriter.close();             outputstream.close();              inputstream inputstream = httpurlconnection.getinputstream();             bufferedreader bufferedreader = new bufferedreader(new inputstreamreader(inputstream,"iso-8859-1"));             string result="";             string line1="";             while((line1 = bufferedreader.readline())!= null) {                 result += line1;             }             bufferedreader.close();             inputstream.close();             httpurlconnection.disconnect();               return result;            }         catch (malformedurlexception e)         {             e.printstacktrace();         }         catch (ioexception e)         {             e.printstacktrace();         }                 {             if(is!=null)             {                 try                 {                     is.close();                 }                 catch (ioexception e)                 {                     e.printstacktrace();                 }             }         }         return  null;     } }  public class fragmentcontrol extends fragmentpageradapter{      public fragmentcontrol(fragmentmanager fm) {         super(fm);     }      @override     public fragment getitem(int position) {          switch(position)         {             case 0:                 tab1fragment tablfragment = new tab1fragment();                 return tablfragment;             case 1:                 tab3fragment tab3fragment = new tab3fragment();                 return tab3fragment;             /*case 2:                 tab3fragment tab3fragment = new tab3fragment();                 return tab3fragment;*/             default:                 return null;         }     }      @override     public int getcount() {         return 2;     }      @override     public charsequence getpagetitle(int position) {         switch(position)         {             case 0 :                 return "delivering";             case 1 :                 return "postponed";            /* case 2 :                 return "postponed";*/         }         return null;     }  } 

you should post code, can find wrong.

in other hand, should check tutorial :

https://www.youtube.com/watch?v=bnpwgi_hggg

i suggest check code , find differ yours.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -