android studio - OnCreate not allowing textView to update in fragment? -


i having issues updating textview in 1 of fragments , cannot seem figure out why. while reading post saw mention how oncreate method kept refreshing did not allow settext update, fixed using sharedpreferences in oncreate seems lot change 1 textview.

when run debug seems indicate settext functioning leads me believe not updating live view. know why happening?

thanks again!

debug log:

this = {tab1fragment@4835} "tab1fragment{2234399 #0 id=0x7f0d0077 frag}" text = "yes" dayview = {appcompattextview@4840}  "android.support.v7.widget.appcompattextview{cdb8055 v.ed..... ......i.  0,0-0,0 #7f0d009d app:id/total_sales_day}" 

here mainactivity

public class mainactivity extends appcompatactivity implements  tab1fragment.oncalcclicklistener{ private static final string tag = "mainactivity"; private sectionspageadapter msectionspageadpater; private viewpager mviewpager; tab1fragment tab1fragment = new tab1fragment();   @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); log.d(tag, "oncreate: starting");  //initializing fragmentmanager fragments can communicate fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragmenttransaction.add(r.id.container, tab1fragment); fragmenttransaction.commit();  //declare sections page adapter msectionspageadpater = new sectionspageadapter(getsupportfragmentmanager());  //set view pager sections adapter mviewpager = (viewpager) findviewbyid(r.id.container); setupviewpager(mviewpager);  //create tab layout object , set it's id tabs (mainactivity.xml) tablayout tablayout = (tablayout) findviewbyid(r.id.tabs); tablayout.setupwithviewpager(mviewpager); // }  // create sections page view adapter private void setupviewpager(viewpager viewpager){  sectionspageadapter adapter = new sectionspageadapter(getsupportfragmentmanager()); adapter.addfragment(new tab1fragment(), "day"); adapter.addfragment(new tab2fragment(), "info"); adapter.addfragment(new tab3fragment(), "week"); viewpager.setadapter(adapter); }  //initialise calculator object calculator maincalculator = new calculator();   @override public void calculateclick(int to_calculate) { switch (to_calculate){     case 1:         toast.maketext(getbasecontext(),"working", toast.length_short).show();         maincalculator.freqday = maincalculator.freqday + 1;         maincalculator.freqweek = maincalculator.freqweek + 1;         maincalculator.gettotalday();         tab1fragment.updateinfo();         break; } } 

here fragment

public class tab1fragment extends fragment implements  view.onclicklistener{ private static final string tag = "tab1fragment"; //establishing buttons & methods button btn1; button btn2; textview dayview; oncalcclicklistener oncalcclicklistener;   @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup  container, @nullable bundle savedinstancestate) { view view = inflater.inflate(r.layout.tab1_fragment, container, false);   //connecting buttons xml btn1 = (button) view.findviewbyid(r.id.btn_1); btn1.setonclicklistener(this); btn2 = (button) view.findviewbyid(r.id.btn_2); btn2.setonclicklistener(this); dayview = (textview) view.findviewbyid(r.id.total_sales_day); return view; }  //onclick listener buttons public void setonclicklistener(view.onclicklistener listener) { btn1.setonclicklistener(listener); btn2.setonclicklistener(listener); }   //method bring data activity , set text public void updateinfo(){ toast.maketext(getcontext(),"65", toast.length_short).show(); dayview.settext("test");  } 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -