android - Not able to pass String value through Bundle -


this question serious me , need me regarding this. creating rss feed app combining navigation drawer , view pager tabbed activity. want pass string value 1 fragment other fragment. here thing. working when navigation drawer activity after combining view-pager , string not passing other fragment through bundle, can't find error because not showing error,

this passing string

public class rssfragment extends fragment implements onitemclicklistener {   private progressbar progressbar; private listview listview;  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view view = inflater.inflate(r.layout.fragment_first, container, false);     progressbar = (progressbar) view.findviewbyid(r.id.progressbar);     listview = (listview) view.findviewbyid(r.id.listview);     listview.setonitemclicklistener(this);     return view; }  @override public void onactivitycreated(bundle savedinstancestate) {     super.onactivitycreated(savedinstancestate);     startservice(); }  private void startservice() {     intent intent = new intent(getactivity(), rssservice.class);     getactivity().startservice(intent); }  /**  * once {@link rssservice} finishes task, result sent broadcastreceiver  */ private broadcastreceiver resultreceiver = new broadcastreceiver() {     @override     public void onreceive(context context, intent intent) {         progressbar.setvisibility(view.gone);         list<rssitem> items = (list<rssitem>) intent.getserializableextra(rssservice.items);         if (items != null) {             rssadapter adapter = new rssadapter(getactivity(), items);             listview.setadapter(adapter);         } else {             toast.maketext(getactivity(), "an error occurred while downloading rss feed.",                     toast.length_long).show();         }     } };  @override public void onitemclick(adapterview<?> parent, view view, int position, long id) {     rssadapter adapter = (rssadapter) parent.getadapter();     rssitem item = (rssitem) adapter.getitem(position);       uri uri = uri.parse(item.getdescription());     string string;     string=uri.tostring();        result des_1=new result();     fragmentmanager fragmentmanager1 =getactivity().getsupportfragmentmanager();     fragmentmanager1.begintransaction().replace(r.id.content_main_layout_frame,des_1 ).addtobackstack("fragback").commit();        result ldf = new result();     bundle args = new bundle();     args.putstring("yourkey", string);     ldf.setarguments(args);     getfragmentmanager().begintransaction().add(r.id.content_main_layout_frame, ldf).commit();  }  @override public void onstart() {     super.onstart();     intentfilter intentfilter = new intentfilter(rssservice.action_rss_parsed);     localbroadcastmanager.getinstance(getactivity()).registerreceiver(resultreceiver, intentfilter); }  @override public void onstop() {     super.onstop();     localbroadcastmanager.getinstance(getactivity()).unregisterreceiver(resultreceiver); } } 

this how receiving string

public class result extends fragment {   public result() {       // required empty public constructor }   @override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     view rootview=inflater.inflate(r.layout.fragment_result,container,false);      bundle bundle = getarguments();      textview textview=(textview)rootview.findviewbyid(r.id.distext);          if(bundle != null) {          string value = bundle.getstring("yourkey");          textview.settext(value);        //  toast.maketext(getactivity(), value,             //   toast.length_long).show();      }          return rootview; }  } 

i pleasing figure out. repeat working not

it fragment

public class datafragment extends fragment { view view; viewpager viewpager; tablayout tablayout;   @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {     view= inflater.inflate(r.layout.sample,container,false);       viewpager = (viewpager) view.findviewbyid(r.id.viewpager);     viewpager.setadapter(new slideradapter(getchildfragmentmanager()));     tablayout = (tablayout) view.findviewbyid(r.id.sliding_tabs);     tablayout.post(new runnable() {         @override         public void run() {             tablayout.setupwithviewpager(viewpager);         }     });      return view;  }     private class slideradapter extends fragmentpageradapter{      final  string tabs[]={"tab1", "tab2","tab3"};     public slideradapter(fragmentmanager fm) {         super(fm);     }       @override     public fragment getitem(int position) {         fragment fragment = null;         switch (position){             case 0:                 fragment = new rssfragment();                 break;             case 1:                 fragment = new rssfragment();                 break;             case 2:                 fragment = new rssfragment();                 break;         }         return fragment;     }       @override     public int getcount() {          return 3;     }    @override    public charsequence getpagetitle(int position) {         return tabs[position];    } }     } 

try below one,

ldf = new result();  bundle bundle = new bundle(); fragmenttransaction fragmenttransaction =  getactivity().getsupportfragmentmanager().begintransaction(); bundle.putstring("key","value"); ldf.setarguments(bundle); fragmenttransaction.addtobackstack("fragback"); fragmenttransaction.replace(r.id.content_main_layout_frame, ldf); fragmenttransaction.commit(); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -