List of usage examples for android.widget TabHost setup
public void setup()
Call setup() before adding tabs if loading TabHost using findViewById().
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 ww w .java 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.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.android.packageinstaller.GrantActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mPm = getPackageManager();//from w w w . j av a2s .c o m mRequestingPackage = this.getCallingPackage(); requested_permissions = getRequestedPermissions(); if (requested_permissions.length == 0) { // The grant request was empty. Return success setResult(RESULT_OK); finish(); return; } PackageInfo pkgInfo = getUpdatedPackageInfo(); AppSecurityPermissions perms = new AppSecurityPermissions(this, pkgInfo); if (perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) == 0) { // The updated permissions dialog said there are no new permissions. // This should never occur if requested_permissions.length > 0, // but we check for it anyway, just in case. setResult(RESULT_OK); finish(); return; } setContentView(R.layout.install_start); ((TextView) findViewById(R.id.install_confirm_question)).setText(R.string.grant_confirm_question); PackageUtil.AppSnippet as = new PackageUtil.AppSnippet(mPm.getApplicationLabel(pkgInfo.applicationInfo), mPm.getApplicationIcon(pkgInfo.applicationInfo)); PackageUtil.initSnippetForNewApp(this, as, R.id.app_snippet); mOk = (Button) findViewById(R.id.ok_button); mOk.setText(R.string.ok); mCancel = (Button) findViewById(R.id.cancel_button); mOk.setOnClickListener(this); mCancel.setOnClickListener(this); TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); View newTab = perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW); View allTab = getPermissionList(perms); adapter.addTab(tabHost.newTabSpec("new").setIndicator(getText(R.string.newPerms)), newTab); adapter.addTab(tabHost.newTabSpec("all").setIndicator(getText(R.string.allPerms)), allTab); }
From source file:com.google.adsensequickstart.CustomReportConfigFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.custom_report_config, container, false); TabHost host = (TabHost) rootView.findViewById(R.id.tabhost); host.setup(); TabSpec spec = host.newTabSpec("Dimensions"); spec.setContent(R.id.dimensions_tab); spec.setIndicator("Dimensions"); host.addTab(spec);/* ww w . j a v a 2 s . c o m*/ spec = host.newTabSpec("Metrics"); spec.setContent(R.id.metrics_tab); spec.setIndicator("Metrics"); host.addTab(spec); spec = host.newTabSpec("Dates"); spec.setContent(R.id.dates_tab); spec.setIndicator("Dates"); host.addTab(spec); if (customReportConfigReadyController == null) { return rootView; } List<ReportingMetadataEntry> dimensions = customReportConfigReadyController.getDimensions(); List<ReportingMetadataEntry> metrics = customReportConfigReadyController.getMetrics(); checker = new DimensionsMetricsCompatChecker(metrics, dimensions); // Get a list of dimension IDs ArrayList<String> dimensionIds = new ArrayList<String>(); for (ReportingMetadataEntry dimension : dimensions) { dimensionIds.add(dimension.getId()); } // Get a list of metric IDs ArrayList<String> metricIds = new ArrayList<String>(); for (ReportingMetadataEntry metric : metrics) { metricIds.add(metric.getId()); } dimensionsUI = new ArrayList<UiReportingItem>(); for (String dimension : dimensionIds) { dimensionsUI.add(new UiReportingItem(dimension, false, true)); } dimensionAdapter = new DimensionMetricAdapter(getActivity(), R.layout.custom_report_list_item, dimensionsUI, false); ListView lvdimension = (ListView) rootView.findViewById(R.id.dimensions_list); lvdimension.setAdapter(dimensionAdapter); metricsUI = new ArrayList<UiReportingItem>(); for (String metric : metricIds) { metricsUI.add(new UiReportingItem(metric, false, true)); } metricAdapter = new DimensionMetricAdapter(getActivity(), R.layout.custom_report_list_item, metricsUI, true); ListView lvmetric = (ListView) rootView.findViewById(R.id.metrics_list); lvmetric.setAdapter(metricAdapter); dimensionAdapter.setChangeListener(this); metricAdapter.setChangeListener(this); rootView.findViewById(R.id.generate_bt).setOnClickListener(this); rootView.findViewById(R.id.from_bt).setOnClickListener(this); rootView.findViewById(R.id.to_bt).setOnClickListener(this); return rootView; }
From source file:com.mychild.view.Parent.CustomTabActivity.java
public void setUpTab() { final TabHost tabHost = (TabHost) findViewById(R.id.tabhost2); tabHost.setup(); tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider); class TabDef { public final String Indicator;//, Content; public TabDef(String Indicator, ListView lv) { this.Indicator = Indicator; //this.Content = Content; } /*TabDef*/ }//from w ww . java 2s. com ; /*TabDef*/ for (TabDef thisTab : new TabDef[] { new TabDef("Exams", examsListView), new TabDef("Results", examsListView) }) { // final TextView contentview = new TextView(this); // contentview.setText(thisTab.Content); View indicatorview = android.view.LayoutInflater.from(this).inflate(R.layout.tabs_bg_plain, null); TextView tabTitle = (TextView) indicatorview.findViewById(R.id.tabsText); tabTitle.setText(thisTab.Indicator); tabHost.addTab(tabHost.newTabSpec(thisTab.Indicator).setIndicator(indicatorview) .setContent(new TabHost.TabContentFactory() { public View createTabContent(String tag) { Log.i("Tagggggg:", tag); if (tag == "Exams") { return examsListView; } else { return examsListView; } } /*createTabContent*/ }));/*TabContentFactory*/ } /*for*/ }
From source file:com.swiftnav.piksidroid.MainActivity.java
private void setupUI() { TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); TabHost.TabSpec tabSpec = tabHost.newTabSpec("Piksi"); tabSpec.setContent(R.id.piksi);/*from w ww .j a v a2 s .c o m*/ tabSpec.setIndicator("Piksi"); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("Tracking"); tabSpec.setContent(R.id.tracking); tabSpec.setIndicator("Tracking"); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("Map"); tabSpec.setContent(R.id.map); tabSpec.setIndicator("Map"); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("Observation"); tabSpec.setContent(R.id.observation); tabSpec.setIndicator("Observation"); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("RTK"); tabSpec.setContent(R.id.rtk); tabSpec.setIndicator("RTK"); tabHost.addTab(tabSpec); tabHost.setOnTabChangedListener(tabChanger); ((EditText) findViewById(R.id.console)).setText("Piksi not connected!"); ((EditText) findViewById(R.id.console)).setTextIsSelectable(false); findViewById(R.id.console).setClickable(false); findViewById(R.id.scrollView).setClickable(false); findViewById(R.id.scrollView).setFocusable(false); findViewById(R.id.scrollView).setOnTouchListener(null); findViewById(R.id.scrollView).setPressed(false); com.swiftnav.piksidroid.MapFragment mFrag = ((com.swiftnav.piksidroid.MapFragment) getFragmentManager() .findFragmentById(R.id.map_fragment)); com.google.android.gms.maps.MapFragment mGFrag = (com.google.android.gms.maps.MapFragment) mFrag .getChildFragmentManager().findFragmentById(R.id.gmap_fragment); mGFrag.getMapAsync(mFrag); View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); }
From source file:com.jtechme.apphub.privileged.views.InstallConfirmActivity.java
private void startInstallConfirm() { final Drawable appIcon = mAppDiff.mPkgInfo.applicationInfo.loadIcon(mPm); final String appLabel = (String) mAppDiff.mPkgInfo.applicationInfo.loadLabel(mPm); View appSnippet = findViewById(R.id.app_snippet); ((ImageView) appSnippet.findViewById(R.id.app_icon)).setImageDrawable(appIcon); ((TextView) appSnippet.findViewById(R.id.app_name)).setText(appLabel); TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override//w w w .jav a 2 s. com public void onTabChanged(String tabId) { } }); boolean permVisible = false; mScrollView = null; mOkCanInstall = false; int msg = 0; AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo); if (mAppDiff.mInstalledAppInfo != null) { msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system : R.string.install_confirm_update; mScrollView = new CaffeinatedScrollView(this); mScrollView.setFillViewport(true); final boolean newPermissionsFound = perms.getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0; if (newPermissionsFound) { permVisible = true; mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW)); } else { throw new RuntimeException( "This should not happen. No new permissions were found but InstallConfirmActivity has been started!"); } adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView); } else { findViewById(R.id.tabscontainer).setVisibility(View.GONE); findViewById(R.id.divider).setVisibility(View.VISIBLE); } final int np = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL); final int nd = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE); if (np > 0 || nd > 0) { permVisible = true; LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View root = inflater.inflate(R.layout.permissions_list, null); if (mScrollView == null) { mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview); } final ViewGroup privacyList = (ViewGroup) root.findViewById(R.id.privacylist); if (np > 0) { privacyList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_PERSONAL)); } else { privacyList.setVisibility(View.GONE); } final ViewGroup deviceList = (ViewGroup) root.findViewById(R.id.devicelist); if (nd > 0) { deviceList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_DEVICE)); } else { root.findViewById(R.id.devicelist).setVisibility(View.GONE); } adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root); } if (!permVisible) { if (mAppDiff.mInstalledAppInfo != null) { // This is an update to an application, but there are no // permissions at all. msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system_no_perms : R.string.install_confirm_update_no_perms; } else { // This is a new application with no permissions. msg = R.string.install_confirm_no_perms; } tabHost.setVisibility(View.GONE); findViewById(R.id.filler).setVisibility(View.VISIBLE); findViewById(R.id.divider).setVisibility(View.GONE); mScrollView = null; } if (msg != 0) { ((TextView) findViewById(R.id.install_confirm)).setText(msg); } mInstallConfirm.setVisibility(View.VISIBLE); mOk = (Button) findViewById(R.id.ok_button); mCancel = (Button) findViewById(R.id.cancel_button); mOk.setOnClickListener(this); mCancel.setOnClickListener(this); if (mScrollView == null) { // There is nothing to scroll view, so the ok button is immediately // set to install. mOk.setText(R.string.menu_install); mOkCanInstall = true; } else { mScrollView.setFullScrollAction(new Runnable() { @Override public void run() { mOk.setText(R.string.menu_install); mOkCanInstall = true; } }); } }
From source file:org.fdroid.fdroid.installer.InstallConfirmActivity.java
private void startInstallConfirm() { final Drawable appIcon = mAppDiff.mPkgInfo.applicationInfo.loadIcon(mPm); final String appLabel = (String) mAppDiff.mPkgInfo.applicationInfo.loadLabel(mPm); View appSnippet = findViewById(R.id.app_snippet); ((ImageView) appSnippet.findViewById(R.id.app_icon)).setImageDrawable(appIcon); ((TextView) appSnippet.findViewById(R.id.app_name)).setText(appLabel); TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); TabsAdapter adapter = new TabsAdapter(this, tabHost, viewPager); adapter.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override// ww w . j a v a2s.co m public void onTabChanged(String tabId) { } }); boolean permVisible = false; mScrollView = null; mOkCanInstall = false; int msg = 0; if (mAppDiff.mPkgInfo != null) { AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo); final int NP = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL); final int ND = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE); if (mAppDiff.mInstalledAppInfo != null) { msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system : R.string.install_confirm_update; mScrollView = new CaffeinatedScrollView(this); mScrollView.setFillViewport(true); final boolean newPermissionsFound = (perms .getPermissionCount(AppSecurityPermissions.WHICH_NEW) > 0); if (newPermissionsFound) { permVisible = true; mScrollView.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_NEW)); } else { throw new RuntimeException( "This should not happen. No new permissions were found but InstallConfirmActivity has been started!"); } adapter.addTab(tabHost.newTabSpec(TAB_ID_NEW).setIndicator(getText(R.string.newPerms)), mScrollView); } else { findViewById(R.id.tabscontainer).setVisibility(View.GONE); findViewById(R.id.divider).setVisibility(View.VISIBLE); } if (NP > 0 || ND > 0) { permVisible = true; LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View root = inflater.inflate(R.layout.permissions_list, null); if (mScrollView == null) { mScrollView = (CaffeinatedScrollView) root.findViewById(R.id.scrollview); } final ViewGroup privacyList = (ViewGroup) root.findViewById(R.id.privacylist); if (NP > 0) { privacyList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_PERSONAL)); } else { privacyList.setVisibility(View.GONE); } final ViewGroup deviceList = (ViewGroup) root.findViewById(R.id.devicelist); if (ND > 0) { deviceList.addView(perms.getPermissionsView(AppSecurityPermissions.WHICH_DEVICE)); } else { root.findViewById(R.id.devicelist).setVisibility(View.GONE); } adapter.addTab(tabHost.newTabSpec(TAB_ID_ALL).setIndicator(getText(R.string.allPerms)), root); } } if (!permVisible) { if (mAppDiff.mInstalledAppInfo != null) { // This is an update to an application, but there are no // permissions at all. msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? R.string.install_confirm_update_system_no_perms : R.string.install_confirm_update_no_perms; } else { // This is a new application with no permissions. msg = R.string.install_confirm_no_perms; } tabHost.setVisibility(View.GONE); findViewById(R.id.filler).setVisibility(View.VISIBLE); findViewById(R.id.divider).setVisibility(View.GONE); mScrollView = null; } if (msg != 0) { ((TextView) findViewById(R.id.install_confirm)).setText(msg); } mInstallConfirm.setVisibility(View.VISIBLE); mOk = (Button) findViewById(R.id.ok_button); mCancel = (Button) findViewById(R.id.cancel_button); mOk.setOnClickListener(this); mCancel.setOnClickListener(this); if (mScrollView == null) { // There is nothing to scroll view, so the ok button is immediately // set to install. mOk.setText(R.string.menu_install); mOkCanInstall = true; } else { mScrollView.setFullScrollAction(new Runnable() { @Override public void run() { mOk.setText(R.string.menu_install); mOkCanInstall = true; } }); } }
From source file:paarmann.physikprofil.MainActivity.java
private void initTabs() { TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); TabHost.TabSpec tsHA = tabHost.newTabSpec("TAB_HA"); tsHA.setIndicator("Hausaufgaben"); tsHA.setContent(R.id.tabHA);/*from w ww. j a va2s.c o m*/ tabHost.addTab(tsHA); TabHost.TabSpec tsDates = tabHost.newTabSpec("TAB_DATES"); tsDates.setIndicator("Termine"); tsDates.setContent(R.id.tabDates); tabHost.addTab(tsDates); }
From source file:com.android.firewall.FirewallListPage.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); FragmentManager manager = getFragmentManager(); // tabhost/*from w ww .j a v a2s . co m*/ TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); // viewpager pager = (ViewPager) findViewById(R.id.pager); adapter = new MainPagerAdapter(manager, this, tabHost, pager); // tab size from screen size DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int tabWidth = metrics.widthPixels / 3; int tabHeight = metrics.widthPixels / 7; for (int i = 0; i < 3; i++) { TabSpec spec = tabHost.newTabSpec("tab" + i); spec.setIndicator(getTabView(tabWidth, tabHeight, TAB_TITLES[i])); adapter.addTab(spec, "tab" + i); } this.handleIntent(); }
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 {// w w w . ja va 2s. c o 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)); } }); }