mainactivity.java | |
File Size: | 2 kb |
File Type: | java |
package c.test2;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.TabActivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;
/*********************************************************************************************
* MainActivity Class/Activity
* This activity takes care of the menu in the application using ActivityGroup. this is also
where the activities for each menu item are set and started through the tabHost object.
* A better way to go about doing this in the future would be through some sort of fragmentation
where instead of having multiple differnet activities, you would have this main activity
that is just fragmented into pieces so that all of the data is centralized.
*********************************************************************************************/
public class MainActivity extends ActivityGroup {
TabHost host;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle extras = getIntent().getExtras(); //grabs data sent from previous activity
String me = extras.getString("user"); //sets that data
host = (TabHost)findViewById(R.id.tabHost);
host.setup(this.getLocalActivityManager());
//Tab calls/starts a new activity when activated
TabHost.TabSpec spec = host.newTabSpec("Tab1");
Intent i = new Intent(this, Tab1.class);
i.putExtra("user", me);
spec.setContent(i);
spec.setIndicator("Friends");
host.addTab(spec);
//Tab calls/starts a new activity when activated
spec = host.newTabSpec("Tab2");
Intent j = new Intent(this, Tab3.class);
j.putExtra("user", me);
spec.setContent(j);
spec.setIndicator("Settings");
host.addTab(spec);
//empty tab
spec = host.newTabSpec("Tab3");
spec.setContent(R.id.linearLayout3);
spec.setIndicator("Notification");
host.addTab(spec);
}
}
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.TabActivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;
/*********************************************************************************************
* MainActivity Class/Activity
* This activity takes care of the menu in the application using ActivityGroup. this is also
where the activities for each menu item are set and started through the tabHost object.
* A better way to go about doing this in the future would be through some sort of fragmentation
where instead of having multiple differnet activities, you would have this main activity
that is just fragmented into pieces so that all of the data is centralized.
*********************************************************************************************/
public class MainActivity extends ActivityGroup {
TabHost host;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle extras = getIntent().getExtras(); //grabs data sent from previous activity
String me = extras.getString("user"); //sets that data
host = (TabHost)findViewById(R.id.tabHost);
host.setup(this.getLocalActivityManager());
//Tab calls/starts a new activity when activated
TabHost.TabSpec spec = host.newTabSpec("Tab1");
Intent i = new Intent(this, Tab1.class);
i.putExtra("user", me);
spec.setContent(i);
spec.setIndicator("Friends");
host.addTab(spec);
//Tab calls/starts a new activity when activated
spec = host.newTabSpec("Tab2");
Intent j = new Intent(this, Tab3.class);
j.putExtra("user", me);
spec.setContent(j);
spec.setIndicator("Settings");
host.addTab(spec);
//empty tab
spec = host.newTabSpec("Tab3");
spec.setContent(R.id.linearLayout3);
spec.setIndicator("Notification");
host.addTab(spec);
}
}