Example usage for android.widget TabHost setup

List of usage examples for android.widget TabHost setup

Introduction

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

Prototype

public void setup() 

Source Link

Document

Call setup() before adding tabs if loading TabHost using findViewById().

Usage

From source file:org.agilespain.kitaos.TalksActivity.java

private void setupTabs() {
    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    ViewPagerTabsAdapter tabsAdapter = new ViewPagerTabsAdapter(this, tabHost, viewPager);
    final TabHost.TabSpec tab1 = createTabSpec(tabHost, TAG_PANEL, R.string.tab_panel);
    tabsAdapter.addTab(tab1, FragmentPanel.class);
    final TabHost.TabSpec tab2 = createTabSpec(tabHost, TAG_TALKS, R.string.tab_talks);
    tabsAdapter.addTab(tab2, FragmentTalks.class);
}

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

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

    try {//from  w  w  w . ja  v  a2s  . c  om
        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.divergentthoughtsgames.colonies.HowToPlayActivity.java

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

    setContentView(R.layout.activity_how_to_play);

    // Parts adapted from 
    // https://github.com/commonsguy/cw-android/blob/master/Fancy/Tab/src/com/commonsware/android/fancy/TabDemo.java
    TabHost tabs = (TabHost) findViewById(R.id.tabhost);
    tabs.setup();

    TabHost.TabSpec spec = tabs.newTabSpec("Overview");
    spec.setContent(R.id.tab1);/*w  w  w . j  a va2s.com*/
    spec.setIndicator("Overview");
    tabs.addTab(spec);

    spec = tabs.newTabSpec("New Colony");
    spec.setContent(R.id.tab2);
    spec.setIndicator("New Colony");
    tabs.addTab(spec);

    spec = tabs.newTabSpec("Goals");
    spec.setContent(R.id.tab3);
    spec.setIndicator("Goals");
    tabs.addTab(spec);
}

From source file:com.infine.android.devoxx.ui.MapHotelFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_map_detail, null);

    final Intent intent = BaseActivity.fragmentArgumentsToIntent(getArguments());
    Bundle extras = intent.getExtras();//from   w  w  w.  j ava  2 s.  c o  m
    if (extras != null) {
        startTab = extras.getInt(EXTRA_ROOM);
    }
    TabHost tabHost = (TabHost) mRootView.findViewById(android.R.id.tabhost);
    tabHost.setup();
    tabHost.addTab(tabHost.newTabSpec(TAG_LEVEL_0).setIndicator(buildIndicator(R.string.tab_map_0))
            .setContent(R.id.tab_map_level0));
    tabHost.addTab(tabHost.newTabSpec(TAG_LEVEL_1).setIndicator(buildIndicator(R.string.tab_map_1))
            .setContent(R.id.tab_map_level1));
    tabHost.setCurrentTab(startTab);

    return mRootView;
}

From source file:com.esminis.server.library.dialog.about.AboutViewImpl.java

public AboutViewImpl(Context context, AboutPresenter presenter) {
    super(context, presenter);
    final LayoutInflater inflater = LayoutInflater.from(context);
    final ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.dialog_about, null);
    final TabHost tabhost = (TabHost) layout.findViewById(R.id.tabhost);
    tabhost.setup();
    addTab(tabhost, context, R.string.manual, viewTextManual = createText(inflater, layout));
    addTab(tabhost, context, R.string.about, viewTextAbout = createText(inflater, layout));
    addTab(tabhost, context, R.string.licenses, viewLicenses = new ProductLicensesViewer(context));
    setupTabTitles(tabhost);//from w  w w .java 2 s.  c om
    setView(layout);
    setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.close), (Message) null);
}

From source file:com.momock.outlet.tab.FragmentTabOutlet.java

public void attach(FragmentTabHolder tabHolder) {
    Logger.check(tabHolder != null, "Parameter tabHolder cannot be null!");
    this.target = tabHolder;
    TabHost tabHost = target.getTabHost();
    final IDataList<IPlug> plugs = getPlugs();
    tabHost.setup();
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override/*w ww .  j a  va2 s.co  m*/
        public void onTabChanged(String tabId) {
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    int index = target.getTabHost().getCurrentTab();
                    int id = target.getTabContentId();
                    ITabPlug plug = (ITabPlug) plugs.getItem(index);
                    setActivePlug(plug);

                    FragmentManager fm = target.getFragmentManager();
                    if (fm != null && plug.getContent() instanceof FragmentHolder) {
                        try {
                            FragmentTransaction ft = fm.beginTransaction();
                            FragmentHolder fh = (FragmentHolder) plug.getContent();
                            ft.replace(id, fh.getFragment());
                            ft.commit();
                            fm.executePendingTransactions();
                        } catch (Exception e) {
                            Logger.error(e);
                        }
                    }
                }

            });
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        if (plug.getContent() instanceof FragmentHolder) {
            TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
            target.setTabIndicator(spec, plug);
            spec.setContent(new TabContentFactory() {

                @Override
                public View createTabContent(String tag) {
                    View v = new View(target.getTabHost().getContext());
                    v.setMinimumWidth(0);
                    v.setMinimumHeight(0);
                    return v;
                }

            });
            tabHost.addTab(spec);
            if (getActivePlug() == plug)
                tabHost.setCurrentTab(i);
        }
    }
}

From source file:org.n52.geoar.data.sos.SOSFeatureVisualization.java

@Override
public View getFeatureView(SpatialEntity2<? extends Geometry> entity, View convertView, ViewGroup parentView,
        Context activityContext) {
    ViewHolder viewHolder;/*ww w.ja  va2 s.  c  o m*/

    if (convertView == null) {
        convertView = LayoutInflater.from(activityContext).inflate(R.layout.sos_featureview, null);
        viewHolder = new ViewHolder();

        viewHolder.textViewServiceSensorId = (TextView) convertView.findViewById(R.id.textViewServiceSensorId);
        viewHolder.textViewDescription = (TextView) convertView.findViewById(R.id.textViewDescription);
        viewHolder.textViewName = (TextView) convertView.findViewById(R.id.textViewName);

        viewHolder.sosObservationView = (SOSObservationView) convertView.findViewById(R.id.sosObservationView);
        viewHolder.sosObservationView.setCapabilitiesCallable(viewHolder.capabilitiesCallable);
        viewHolder.sosObservationView.setObservationCallable(viewHolder.observationCallable);
        viewHolder.sosObservationView.setActivityContext(activityContext);

        TabHost tabHost = (TabHost) convertView.findViewById(android.R.id.tabhost);
        tabHost.setup();
        tabHost.addTab(tabHost.newTabSpec("FOI").setIndicator("Feature").setContent(R.id.scrollViewFOI));
        tabHost.addTab(tabHost.newTabSpec("SOS").setIndicator("Observations").setContent(R.id.layoutSOS));

        tabHost.setCurrentTab(0);

        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    if (entity instanceof FOI) {
        viewHolder.featureOfInterest = (FOI) entity;
        viewHolder.textViewName.setText(viewHolder.featureOfInterest.name);
        if (viewHolder.featureOfInterest.description != null) {
            viewHolder.textViewDescription.setText(Html.fromHtml(viewHolder.featureOfInterest.description));
        }
        viewHolder.textViewServiceSensorId.setText(viewHolder.featureOfInterest.id);
    }
    return convertView;
}

From source file:com.simplaapliko.wakeup.sample.ui.DialogDateTime.java

private void initUiWidgets(View rootView) {
    Log.d(TAG, "initUiWidgets()");

    // set up tabhost
    TabHost tabHost = (TabHost) rootView.findViewById(R.id.tabhost);
    tabHost.setup();

    TabHost.TabSpec tabSpec;/*  w  ww.ja  va  2 s .  c  o m*/

    // adding tabs
    tabSpec = tabHost.newTabSpec("date");
    tabSpec.setIndicator("Date");
    tabSpec.setContent(R.id.date);
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("time");
    tabSpec.setIndicator("Time");
    tabSpec.setContent(R.id.time);
    tabHost.addTab(tabSpec);

    TimePicker timePicker = (TimePicker) rootView.findViewById(R.id.time);
    timePicker.setIs24HourView(true); //set to true, because it is more compact
    timePicker.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

    // init time picker before OnTimeChangedListener() is set
    // otherwise minutes will be set to current time, once setCurrentHour() is called
    timePicker.setCurrentHour(mCalendar.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(mCalendar.get(Calendar.MINUTE));

    timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {

            mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            mCalendar.set(Calendar.MINUTE, minute);
            mCalendar.set(Calendar.SECOND, 0);
        }
    });

    DatePicker datePicker = (DatePicker) rootView.findViewById(R.id.date);
    datePicker.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    datePicker.init(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH),
            mCalendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

                    mCalendar.set(Calendar.YEAR, year);
                    mCalendar.set(Calendar.MONTH, monthOfYear);
                    mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                }
            });
}

From source file:com.example.chilipepper.finalgooglemapsproject.MainActivity.java

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

    lv = (ListView) findViewById(R.id.list);

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

    tabHost.setup();

    TabHost.TabSpec tabSpec = tabHost.newTabSpec("list");
    tabSpec.setContent(R.id.tabList);//w  w  w. jav  a2  s.  co m
    tabSpec.setIndicator("List");
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("Map");
    tabSpec.setContent(R.id.tabMap);
    tabSpec.setIndicator("Map");
    tabHost.addTab(tabSpec);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

    MapFragment mapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
    mapFragment.getMapAsync(this);

}

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();/*w ww .  j  av a 2  s.  c  om*/

    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);
}