i have problem first application,this first question,i have 2 activity , 2 layout
this mainactivit.java
public class mainactivity extends tabactivity { tabhost tabhost; public static int meth; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); loadallvar(); updatehud(meth); tabswitcher(); } public static int loadallvar(){ //load var files (not added now) meth = 200; return meth; } private void updatehud(int meth){ string methstring = integer.tostring(meth); textview textsell = (textview)findviewbyid(r.id.textmethcount); textsell.settext(methstring); } public void tabswitcher() { tabhost = gettabhost(); tabhost.tabspec tab1spec = tabhost.newtabspec("tab1"); tab1spec.setindicator("cook"); intent firstintent = new intent(this, cooktab.class); tab1spec.setcontent(firstintent); tabhost.addtab(tab1spec); } } and second activity
public class cooktab extends activity { public static int meth; public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.cooktab); loadvarfromcook(); checkcookclick(); } public void loadvarfromcook (){ meth = loadallvar(); string methstring = integer.tostring(meth); toast.maketext(getapplicationcontext(),methstring,toast.length_short).show(); } public void checkcookclick (){ button buttoncook = (button) findviewbyid(r.id.buttoncook); buttoncook.setonclicklistener(new button.onclicklistener(){ public void onclick(view v){ meth = meth + 1; toast.maketext(getapplicationcontext() , "+1" , toast.length_short).show(); //here need update value of meth inside activity_main.xml } }); } } this mainactivity layout
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <tabhost android:layout_width="fill_parent" android:layout_height="match_parent" android:id="@android:id/tabhost"> <tabwidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></tabwidget> <framelayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent"></framelayout> </tabhost> <relativelayout android:layout_width="fill_parent" android:layout_height="100dp" android:layout_alignparentbottom="true" android:id="@+id/layouthud"> <textview android:layout_width="50dp" android:layout_height="40dp" android:id="@+id/textmethcount" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_marginleft="28dp" android:layout_marginstart="28dp" /> </relativelayout> </relativelayout> and second tab layout
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_width="100dp" android:layout_height="60dp" android:id="@+id/textmeth" android:layout_margintop="250dp" android:layout_marginleft="145dp" android:text="meth" android:gravity="center" android:textsize="29dp" android:textstyle="bold"/> <button android:layout_width="100dp" android:layout_height="60dp" android:id="@+id/buttoncook" android:layout_below="@+id/textmeth" android:layout_alignleft="@+id/textmeth" android:layout_alignstart="@+id/textmeth" android:text="cook"/> </relativelayout> i need change text inside textview located inside activity_main.xml when press button inside cooktab.xml how can that? findviewbyid() dosen't work
p.s. add 1 tab ,i add more tab think first one
try using eventbus allows call functions in other parts of app. alternatively use standard java interface link
Comments
Post a Comment