You are on page 1of 2

package com.example.

shoppinglist;
import
import
import
import
import
import
import
import
import
import
import

android.support.v7.app.ActionBarActivity;
android.app.TabActivity;
android.content.Intent;
android.os.Bundle;
android.view.LayoutInflater;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.widget.TabHost;
android.widget.TabHost.TabSpec;
android.widget.TextView;

public class ViewActivity extends TabActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_view);
TabHost host = getTabHost();
TabSpec tabAll = host.newTabSpec("all");
View tabIndicator = LayoutInflater.from(this).inflate(
R.layout.apptheme_tab_indicator_holo, host.getTa
bWidget(),
false);
TextView title = (TextView) tabIndicator
.findViewById(android.R.id.title);
title.setText("All");
View tabIndicatorEssential = LayoutInflater.from(this).inflate(
R.layout.apptheme_tab_indicator_holo, host.getTa
bWidget(),
false);
TextView titleEssential = (TextView) tabIndicatorEssential
.findViewById(android.R.id.title);
titleEssential.setText("Essential");
View tabIndicatorStocked = LayoutInflater.from(this).inflate(
R.layout.apptheme_tab_indicator_holo, host.getTa
bWidget(),
false);
TextView titleStocked = (TextView) tabIndicatorStocked
.findViewById(android.R.id.title);
titleStocked.setText("Stocked");
tabAll.setIndicator(tabIndicator);
TabSpec tabEssential = host.newTabSpec("essential");
tabEssential.setIndicator(tabIndicatorEssential);
TabSpec tabStocked = host.newTabSpec("stocked");
tabStocked.setIndicator(tabIndicatorStocked);
Intent intent_all = new Intent(this, ViewAllActivity.class);
Intent intent_essential = new Intent(this, ViewEssentialActivity
.class);
Intent intent_stocked = new Intent(this, ViewStockedActivity.cla

ss);
tabAll.setContent(intent_all);
tabEssential.setContent(intent_essential);
tabStocked.setContent(intent_stocked);
host.addTab(tabAll);
host.addTab(tabEssential);
host.addTab(tabStocked);
host.setCurrentTab(0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.view, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

You might also like