Example usage for android.widget TabHost addTab

List of usage examples for android.widget TabHost addTab

Introduction

In this page you can find the example usage for android.widget TabHost addTab.

Prototype

public void addTab(TabSpec tabSpec) 

Source Link

Document

Add a tab.

Usage

From source file:com.redhorse.quickstart.AppConfig.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    dbStart = new dbStartConfigAdapter(this);
    dbStart.open();//from  w  ww.  ja v a2  s.c o m

    loadApps(); // do this in onresume?

    setContentView(R.layout.applist);
    TabHost mTabHost = (TabHost) findViewById(R.id.tabhost);
    mTabHost.setup();
    LayoutInflater inflater_tab1 = LayoutInflater.from(this);
    inflater_tab1.inflate(R.layout.grid1, mTabHost.getTabContentView());
    inflater_tab1.inflate(R.layout.grid2, mTabHost.getTabContentView());
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1")
            .setIndicator("", getResources().getDrawable(R.drawable.btn_add)).setContent(R.id.list1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2")
            .setIndicator("", getResources().getDrawable(R.drawable.btn_remove)).setContent(R.id.list2));
    mList = (GridView) findViewById(R.id.list1);
    mList.setAdapter(new AppsAdapter());
    mList.setOnItemClickListener(Grid1ItemClickListener);
    mList2 = (GridView) findViewById(R.id.list2);
    mList2.setAdapter(new AppsAdapter2());
    mList2.setOnItemClickListener(Grid2ItemClickListener);
    Button button = (Button) findViewById(R.id.Button01);
    button.setOnClickListener(Button01Listener);
    button = (Button) findViewById(R.id.Button02);
    button.setOnClickListener(Button02Listener);
    button = (Button) findViewById(R.id.weibolist);
    button.setOnClickListener(weibolistListener);
}

From source file:com.tutor.fragment.ViewPageFragment.java

private void initialMainTabHost(LayoutInflater inflater, View mView) {

    View sgTab = inflater.inflate(R.layout.tab_main_widebg, null);
    TextView sgtv = (TextView) sgTab.findViewById(R.id.mainTabTv);
    sgtv.setText("3G");

    View yxTab = inflater.inflate(R.layout.tab_main_widebg, null);
    TextView yxtv = (TextView) yxTab.findViewById(R.id.mainTabTv);
    yxtv.setText("");
    TabHost yxTabHost = (TabHost) mView.findViewById(R.id.yxTabHost);
    yxTabHost.setup();/* w  ww.j a  v  a2  s  . c o  m*/
    yxTabHost.addTab(yxTabHost.newTabSpec("3GTab").setIndicator(sgTab).setContent(R.id.tab_3gfudao));
    yxTabHost.addTab(yxTabHost.newTabSpec("YXJifen").setIndicator(yxTab).setContent(R.id.tab_yxjifen));
    yxTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (tabId.equals("3GTab")) {
                // ListView myTabLst = (ListView)
                // findViewById(R.id.myTabLst);

            } else {

            }
        }

    });
}

From source file:net.yolosec.upckeygen.ui.AboutTabHostActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about_dialog);

    try {// w  ww . j a  v  a 2  s. c o m
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    } catch (Exception e) {
        Log.e(TAG, "Exception", e);
    }

    TabHost tabs = (TabHost) findViewById(R.id.tabhost);
    tabs.setup();

    TabHost.TabSpec tspec1 = tabs.newTabSpec("about");
    tspec1.setIndicator(getString(R.string.pref_2section));
    tspec1.setContent(R.id.text_about_scroll);
    TextView text = ((TextView) findViewById(R.id.text_about));
    text.setMovementMethod(LinkMovementMethod.getInstance());
    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        String version = pInfo.versionName;
        text.append(version);
    } catch (Exception e) {
        Log.e(TAG, "Exception in getting app version", e);
    }
    tabs.addTab(tspec1);

    TabHost.TabSpec tspec2 = tabs.newTabSpec("credits");
    tspec2.setIndicator(getString(R.string.dialog_about_credits));
    tspec2.setContent(R.id.about_credits_scroll);
    ((TextView) findViewById(R.id.about_credits)).setMovementMethod(LinkMovementMethod.getInstance());
    tabs.addTab(tspec2);
    TabHost.TabSpec tspec3 = tabs.newTabSpec("license");
    tspec3.setIndicator(getString(R.string.dialog_about_license));
    tspec3.setContent(R.id.about_license_scroll);
    ((TextView) findViewById(R.id.about_license)).setMovementMethod(LinkMovementMethod.getInstance());
    tabs.addTab(tspec3);
}

From source file:com.initiativaromania.hartabanilorpublici.IRUserInterface.activities.MainActivity.java

private void tabSetup() {
    TabHost tabHost = (TabHost) findViewById(R.id.tabHost);

    tabHost.setup();/* w  w  w  .j av a2s.  co m*/

    View tabView = createTabView(this, TAB_MAP);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab1").setIndicator(tabView).setContent(R.id.tabMap);
    tabHost.addTab(spec);

    tabView = createTabView(this, TAB_STATISTICS);
    spec = tabHost.newTabSpec("tab2").setIndicator(tabView).setContent(R.id.tabStatistics);
    tabHost.addTab(spec);
}

From source file:com.google.sample.castcompanionlibrary.cast.tracks.ui.TracksChooserDialog.java

private void setupView(View view) {
    ListView listView1 = (ListView) view.findViewById(R.id.listview1);
    ListView listView2 = (ListView) view.findViewById(R.id.listview2);
    TextView textEmptyMessageView = (TextView) view.findViewById(R.id.text_empty_message);
    TextView audioEmptyMessageView = (TextView) view.findViewById(R.id.audio_empty_message);
    partitionTracks();//  ww  w .  j  a v a  2  s. c  o  m

    mTextAdapter = new TracksListAdapter(getActivity(), R.layout.tracks_row_layout, mTextTracks,
            mSelectedTextPosition);
    mAudioVideoAdapter = new TracksListAdapter(getActivity(), R.layout.tracks_row_layout, mAudioTracks,
            mSelectedAudioPosition);

    listView1.setAdapter(mTextAdapter);
    listView2.setAdapter(mAudioVideoAdapter);

    TabHost tabs = (TabHost) view.findViewById(R.id.tabhost);
    tabs.setup();

    // create tab 1
    TabHost.TabSpec tab1 = tabs.newTabSpec("tab1");
    if (mTextTracks == null || mTextTracks.isEmpty()) {
        listView1.setVisibility(View.INVISIBLE);
        tab1.setContent(R.id.text_empty_message);
    } else {
        textEmptyMessageView.setVisibility(View.INVISIBLE);
        tab1.setContent(R.id.listview1);
    }
    tab1.setIndicator(getString(R.string.caption_subtitles));
    tabs.addTab(tab1);

    // create tab 2
    TabHost.TabSpec tab2 = tabs.newTabSpec("tab2");
    if (mAudioTracks == null || mAudioTracks.isEmpty()) {
        listView2.setVisibility(View.INVISIBLE);
        tab2.setContent(R.id.audio_empty_message);
    } else {
        audioEmptyMessageView.setVisibility(View.INVISIBLE);
        tab2.setContent(R.id.listview2);
    }
    tab2.setIndicator(getString(R.string.caption_audio));
    tabs.addTab(tab2);
}

From source file:com.google.android.libraries.cast.companionlibrary.cast.tracks.ui.TracksChooserDialog.java

private void setUpView(View view) {
    ListView listView1 = (ListView) view.findViewById(R.id.listview1);
    ListView listView2 = (ListView) view.findViewById(R.id.listview2);
    TextView textEmptyMessageView = (TextView) view.findViewById(R.id.text_empty_message);
    TextView audioEmptyMessageView = (TextView) view.findViewById(R.id.audio_empty_message);
    partitionTracks();/*from   w  ww . ja  va 2s. co m*/

    mTextAdapter = new TracksListAdapter(getActivity(), R.layout.tracks_row_layout, mTextTracks,
            mSelectedTextPosition);
    mAudioVideoAdapter = new TracksListAdapter(getActivity(), R.layout.tracks_row_layout, mAudioTracks,
            mSelectedAudioPosition);

    listView1.setAdapter(mTextAdapter);
    listView2.setAdapter(mAudioVideoAdapter);

    TabHost tabs = (TabHost) view.findViewById(R.id.tabhost);
    tabs.setup();

    // create tab 1
    TabHost.TabSpec tab1 = tabs.newTabSpec("tab1");
    if (mTextTracks == null || mTextTracks.isEmpty()) {
        listView1.setVisibility(View.INVISIBLE);
        tab1.setContent(R.id.text_empty_message);
    } else {
        textEmptyMessageView.setVisibility(View.INVISIBLE);
        tab1.setContent(R.id.listview1);
    }
    tab1.setIndicator(getString(R.string.ccl_caption_subtitles));
    tabs.addTab(tab1);

    // create tab 2
    TabHost.TabSpec tab2 = tabs.newTabSpec("tab2");
    if (mAudioTracks == null || mAudioTracks.isEmpty()) {
        listView2.setVisibility(View.INVISIBLE);
        tab2.setContent(R.id.audio_empty_message);
    } else {
        audioEmptyMessageView.setVisibility(View.INVISIBLE);
        tab2.setContent(R.id.listview2);
    }
    tab2.setIndicator(getString(R.string.ccl_caption_audio));
    tabs.addTab(tab2);
}

From source file:com.facebook.android.FieldsConnectionsDialog.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fields_connections_list);
    LayoutParams params = getWindow().getAttributes();
    params.width = LayoutParams.FILL_PARENT;
    params.height = LayoutParams.FILL_PARENT;
    getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);

    fieldsList = (ListView) findViewById(R.id.fields_list);
    connectionsList = (ListView) findViewById(R.id.connections_list);

    fieldsAdapter = new FieldsListAdapter();
    if (this.fieldsArray == null) {
        fieldsList.setAdapter(new ArrayAdapter<String>(explorerActivity, android.R.layout.simple_list_item_1,
                new String[] { "No fields available" }));
    } else {/*from   w w w.  j  av a 2 s  .  co  m*/
        fieldsList.setAdapter(fieldsAdapter);
    }

    connectionsAdapter = new ConnectionsListAdapter();
    if (this.connectionsArray == null) {
        connectionsList.setAdapter(new ArrayAdapter<String>(explorerActivity,
                android.R.layout.simple_list_item_1, new String[] { "No connections available" }));
    } else {
        connectionsList.setAdapter(connectionsAdapter);
    }

    TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();

    TabSpec spec1 = tabHost.newTabSpec("Tab 1");
    spec1.setIndicator(explorerActivity.getString(R.string.fields));
    spec1.setContent(R.id.fields_layout);

    TabSpec spec2 = tabHost.newTabSpec("Tab 2");
    spec2.setIndicator(explorerActivity.getString(R.string.connections));
    spec2.setContent(R.id.connections_list);

    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.setCurrentTab(0);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = TAB_HEIGHT;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = TAB_HEIGHT;

    mGetFieldsButton = (Button) findViewById(R.id.get_fields_button);
    mGetFieldsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*
             * Source Tag:
             */
            FieldsConnectionsDialog.this.dismiss();
            if (!fieldsVector.isEmpty()) {
                explorerActivity.getFields(fieldsVector);
            } else {
                Toast.makeText(explorerActivity.getBaseContext(), "No Fields selected.", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    connectionsList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
            FieldsConnectionsDialog.this.dismiss();
            explorerActivity.getConnection(connectionsArray.get(position));
        }
    });
}

From source file:com.hector.invoice.views.TabExportInvoiceOrder.java

/**
 * Add Tab content to the Tabhost//from  w  w  w.j a  v a2  s .  c o m
 * 
 * @param activity
 * @param tabHost
 * @param tabSpec
 * @param clss
 * @param args
 */
private void AddTab(BaseFragmentActivity activity, TabHost tabHost, String tabName, int type) {
    View tabview = createTabView(tabHost.getContext(), tabName, type);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    lp.weight = 1;
    lp.gravity = Gravity.CENTER;
    lp.setMargins(0, 0, 0, 0);
    tabview.setLayoutParams(lp);

    TabSpec setContent = tabHost.newTabSpec(tabName).setIndicator(tabview).setContent(new TabFactory(activity));
    tabHost.addTab(setContent);
}

From source file:com.google.android.apps.iosched.ui.SessionDetailActivity.java

/** Build and add "notes" tab. */
private void setupNotesTab() {
    final TabHost host = getTabHost();

    final Uri notesUri = Sessions.buildNotesDirUri(mSessionId);
    final Intent intent = new Intent(Intent.ACTION_VIEW, notesUri);
    intent.addCategory(Intent.CATEGORY_TAB);
    intent.putExtra(NotesActivity.EXTRA_SHOW_INSERT, true);

    // Notes content comes from reused activity
    host.addTab(
            host.newTabSpec(TAG_NOTES).setIndicator(buildIndicator(R.string.session_notes)).setContent(intent));
}

From source file:edu.nd.darts.cimon.NDroidAdmin.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.administrator);
    // Toast.makeText(getBaseContext(), "This is",
    // Toast.LENGTH_LONG).show();

    startService(new Intent(this, NDroidService.class));

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec; // Reusable TabSpec for each tab
    Intent intent; // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    // intent = new Intent().setClass(this, NDroidSystem.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_SYSTEM);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("system").setIndicator("System", res.getDrawable(R.drawable.icon_system))
            .setContent(intent);/* w  w  w .j  a  v a  2 s  .c  o  m*/
    tabHost.addTab(spec);

    // Do the same for the other tabs
    // intent = new Intent().setClass(this, NDroidSensor.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_SENSOR);
    spec = tabHost.newTabSpec("sensors").setIndicator("Sensors", res.getDrawable(R.drawable.icon_sensor))
            .setContent(intent);
    tabHost.addTab(spec);

    // intent = new Intent().setClass(this, NDroidUser.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_USER);
    spec = tabHost.newTabSpec("user").setIndicator("User Activity", res.getDrawable(R.drawable.icon_user))
            .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);

    SharedPreferences appPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);

    int storedVersion = appPrefs.getInt(PREF_VERSION, -1);

    int appVersion = -1;

    try {
        appVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (DebugLog.DEBUG)
        Log.d(TAG, "NDroidAdmin.onCreate - appVersion:" + appVersion + " storedVersion:" + storedVersion);

    if (appVersion > storedVersion) {

        new Thread(new Runnable() {
            public void run() {
                List<MetricService<?>> serviceList;
                serviceList = MetricService.getServices(Metrics.TYPE_SYSTEM);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
                serviceList = MetricService.getServices(Metrics.TYPE_SENSOR);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
                serviceList = MetricService.getServices(Metrics.TYPE_USER);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
            }
        }).start();

        SharedPreferences.Editor editor = appPrefs.edit();
        editor.putInt(PREF_VERSION, appVersion);
        editor.commit();
    }
}