java - How to "run method" from different android class -


first , foremost, many, have began try , learn java , android development. following tutorials , on. anyhow, attempting simple unsure of syntax complete, , because of such, not sure how search on internet success.

my question: have "main.java" file , second "tabs.java". main has expect default stub:

package com.example.main;  import android.os.bundle; import android.app.activity; import android.view.menu;  public class main extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }  } 

my tabs.java looks like:

package com.example.main;  import android.app.activity; import android.os.bundle; import android.widget.tabhost; import android.widget.tabhost.tabspec;  public class tabs extends activity{      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.tabs);          //initiate tabs         tabhost th = (tabhost)findviewbyid(r.id.tabhost);         th.setup();          //create tab1         tabspec specs = th.newtabspec("tag1");         specs.setcontent(r.id.tab1);         specs.setindicator("reservation list");         th.addtab(specs);     } } 

my hope initiate tabs class on program start, setup tabbed view. throw main class thought attempt keep code neater separating them out. how can go completing this?

the "answer" bad idea. however, think worth explaining why bad idea. sounds confusing 2 fundimental concepts - of class, exists in object oriented languages java, , of android activity.

an activity seperate program. contains (or @ least most) of material needs perform specific task. app can combine number of activities handle more 1 kind of task - example, in messaging application, may have 1 activity displays users contacts , allows send them message. these activities seperate. can transfer data between them, @codemagic mentioned, using intents part each activity self contained.

a class concept object oriented programming serves blueprint objects of type created. oracle java documentation provides example of concept. classes useful becuase alow set properties of kind of object can used later on in application, improving flexibility.

the chat application example references above way understand where/how use class. in sitaution, when had display person's contact list, not able know in advance each user contained in list, information provided or how many individuals there be. deal situation create class called user. user class contain details wanted display particular person. maybe include name, address, phone number, whatever. set list of properties apply users , later create individual instances of user class, , fill in supplied data, each person wish display.

in short - you're activity not work same way class (but see fragments can behave similarly). trying do, create tabs in main activity.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -