Search Results

Search found 105 results on 5 pages for 'tabhost'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • TabHost / TabWidget - Scale Background Image ?

    - by user359519
    I need to scale my TabWidget background images so they maintain aspect ratio. I am using a TabHost with a TabWidget. I am then using setBackgroundDrawable to set the images. I found a close answer here - Background in tab widget ignore scaling. However, I'm not sure just where to add the new Drawable code. (Working with the HelloTabWidget example, none of my modules use RelativeLayout, and I don't see any layout for "tabcontent".) I also found this thread - Android: Scale a Drawable or background image?. According to it, it sounds like I would have to pre-scale my images, which defeats the whole purpose of making them scaleable. I also found another thread where someone subclassed the Drawable class so it would either not scale, or it would scale properly. I can't find it now, but that seems like a LOT to go through when you should just be able to do something simple like mTab.setScaleType(centerInside). Here's my code: main.xml: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/main_background"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"/> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0"/> </LinearLayout> </TabHost> main activity: tabHost.setOnTabChangedListener(new OnTabChangeListener() { TabHost changedTabHost = getTabHost(); TabWidget changedTabWidget = getTabWidget(); View changedView = changedTabHost.getTabWidget().getChildAt(0); public void onTabChanged(String tabId) { int selectedTab = changedTabHost.getCurrentTab(); TabWidget tw = getTabWidget(); if(selectedTab == 0) { //setTitle("Missions Timeline"); View tempView = tabHost.getTabWidget().getChildAt(0); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_timeline_on)); tempView = tabHost.getTabWidget().getChildAt(1); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_map_off)); tempView = tabHost.getTabWidget().getChildAt(2); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_search_off)); tempView = tabHost.getTabWidget().getChildAt(3); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_news_off)); tempView = tabHost.getTabWidget().getChildAt(4); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_license_off)); //ImageView iv = (ImageView)tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.icon); //iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_timeline_on)); //iv = (ImageView)tabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.icon); //iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_map_off)); } else if (selectedTab == 1) { //setTitle("Spinoffs Around You"); View tempView = tabHost.getTabWidget().getChildAt(0); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_timeline_off)); tempView = tabHost.getTabWidget().getChildAt(1); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_map_on)); tempView = tabHost.getTabWidget().getChildAt(2); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_search_off)); tempView = tabHost.getTabWidget().getChildAt(3); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_news_off)); tempView = tabHost.getTabWidget().getChildAt(4); tempView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_license_off)); } I also tried 9patch images, but they wind up being too small. So, what's the best way to go about this?

    Read the article

  • Using Bundle and Intent with TabHost

    - by apesa
    I am using TabHost with 3 tabs. I need to pass the params selected from one screen using Bundle and / or Intent to the next and then set the correct tab in TabHost and pass those params to the correct tab. I hope that makes sense. I have a config screen that has several radio buttons that are grouped and 1 checkbox and a button. in my onClick() I have the following code. public class Distribute extends Activity implements OnClickListener { DistributionMap gixnav; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textview = new TextView(this); textview.setText("Distribution"); setContentView(R.drawable.configup); Button button = (Button)findViewById(R.id.btn_configup1); button.setOnClickListener(this); } public void onClick(View v) { Intent intent; Bundle extras = new Bundle(); intent = new Intent().setClass(getApplicationContext(), Clevel.class); intent.putExtras(extras); startActivity(intent); } } I need to pass the selection params (which radio button is selected and is the checkbox clicked to Clevel. In Clevel I have to parse the bundle and operate on those params. Basiclaly I will be pulling data froma DB and using that data to call google maps ItemizedOverlay. onClick calls Clevel.class using Intent. This works and I understand how Intent works. What I need to understand is how to grab or reference the selected radio button and whatever else may be clicked or checked and pass it through TabHost to the correct Tab. This is what I have in Clevel for TabHost. From TabHost the onCLick will need to pass everything to Distribute.class public class Clevel extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gixout1); Resources res = getResources(); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent; String mData; Bundle extras = getIntent().getExtras(); if (extras != null) { mData = extras.getString("key"); } intent = new Intent().setClass(this, ClevelMain.class); spec = tabHost.newTabSpec("Main").setIndicator("C-Level", res.getDrawable(R.drawable.gixmain)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, Distribute.class); spec = tabHost.newTabSpec("Config").setIndicator("Distribute", res.getDrawable(R.drawable.gixconfig)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, DistributionMap.class); spec = tabHost.newTabSpec("Nav").setIndicator("Map", res.getDrawable(R.drawable.gixnav)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(3); tabHost.getOnFocusChangeListener(); } I am really looking for some pointers on how to pass and use params in Bundle and whether in should use Bundle and Intent or can I just use Intent? Thanks in advance, Pat

    Read the article

  • TabHost remove all content activities

    - by tiex
    I have a code for populating content for tabs dynamically. First time it works ok, but when I want to replace tabs (and their content) with new content - tabs are changed but tabs' contents are not, how can I clear completely whole TabHost and replace with other content? TabHost tabHost = getTabHost(); Intent intent; TabHost.TabSpec spec; tabHost.setCurrentTab(0); tabHost.clearAllTabs(); int idx = 0; for(Group g: c.getGroups()){ intent = new Intent().setClass(this, GroupActivity.class); ItemLookup.createForGroup(idx).putToIntent(intent); spec = tabHost .newTabSpec("tab"+idx) .setIndicator(g.getTitle()) .setContent(intent); tabHost.addTab(spec); idx++; } tabHost.setCurrentTab(0);

    Read the article

  • TabHost disappears after locking the phone and reopening it:

    - by Emil Adz
    I have a weird issue with my TabHost in my FragmentActivity that contains a ViewPager. The problem is that when I close my phone (press the power button) while I use my application, and then I turn back the phone and my application gets reopened, at this point my TabHost is missing. So the closing of my phone is causes the TabHost to disappear. My guess would be that I need to save my tabHost state in the saveInstanceState object, and restore it in onResume I only have no idea how it's done. here is my code for the FragmentActivity: public class TabsViewPagerFragmentActivity extends FragmentActivity implements ViewPager.OnPageChangeListener, TabHost.OnTabChangeListener { static final String TAG = TabsViewPagerFragmentActivity.class.getSimpleName(); private TabHost mTabHost; private ViewPager mViewPager; private HashMap<String, TabInfo> mapTabInfo; public ViewPagerAdapter mPagerAdapter; private TextView tvReportName, tvTabTitle; private Button bBackToParameters; private Dialog progressDialog; private SGRaportManagerAppObj application; private int numberOfTabs = 0; private Display display; public static final int POPUP_MARGIN = 6; LeftSideMenu leftSideMenu; public void NotifyTabActivityViewPagerAdapter() { mPagerAdapter.notifyDataSetChanged(); } public ViewPagerAdapter getTabActivityViewPagerAdapter() { return mPagerAdapter; } public ViewPager getTabActivityViewPager() { return mViewPager; } public void setCurrentTabTitle (String title) { tvTabTitle.setText(title); Log.d(TAG, "set tab title from activity: "+title); } /** * Maintains extrinsic info of a tab's construct */ private class TabInfo { private String tag; private Class<?> clss; private Bundle args; private Fragment fragment; TabInfo(String tag, Class<?> clazz, Bundle args) { this.tag = tag; this.clss = clazz; this.args = args; } } /** * A simple factory that returns dummy views to the Tabhost */ class TabFactory implements TabContentFactory { private final Context mContext; /** * @param context */ public TabFactory(Context context) { mContext = context; } /** (non-Javadoc) * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String) */ public View createTabContent(String tag) { View v = new View(mContext); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } } /** (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); application = SGRaportManagerAppObj.getInstance(); display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); // Inflate the layout setContentView(R.layout.tabs_screen_activity_layout); tvTabTitle = (TextView) findViewById(R.id.tvTabName); tvReportName = (TextView)findViewById(R.id.tvReportName); tvReportName.setText(application.currentReport.getName()+ " - "); bBackToParameters = (Button) findViewById(R.id.bBackToParameters); leftSideMenu = (LeftSideMenu) findViewById(R.id.leftSideMenu); applyOnClickListenerToLeftSideMenu(); findViewById(R.id.showLeftMenuButton).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Display d = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = d.getWidth(); View panel = findViewById(R.id.leftSideMenu); View appPanel = findViewById(R.id.appLayout); if (panel.getVisibility() == View.GONE){ appPanel.setLayoutParams(new LinearLayout.LayoutParams(width, LayoutParams.FILL_PARENT)); panel.setVisibility(View.VISIBLE); applyOnClickListenerToLeftSideMenu(); }else{ ToggleButton button = (ToggleButton) findViewById(R.id.showLeftMenuButton); button.setChecked(false); panel.setVisibility(View.GONE); } } }); // Initialise the TabHost progressDialog = DialogUtils.createProgressDialog(this, this.getString(R.string.populating_view_pager)); progressDialog.show(); if (SGRaportManagerAppObj.getInstance().parametersRepository.getParametersRepository().size() == 0) { bBackToParameters.setText(R.string.back_to_report_list); } this.initialiseTabHost(savedInstanceState); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state } // Intialise ViewPager this.intialiseViewPager(); progressDialog.dismiss(); } /** (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle) */ protected void onSaveInstanceState(Bundle outState) { outState.putString("tab", mTabHost.getCurrentTabTag()); //save the tab selected super.onSaveInstanceState(outState); } /** * Initialise ViewPager */ public void intialiseViewPager() { List<Fragment> fragments = new Vector<Fragment>(); // TabInfo tabInfo = null; if (application.getCurrentDataSource().equals(DataSource.SSRS)) { numberOfTabs = application.currentReport.getTabsList().size(); } else if (application.getCurrentDataSource().equals(DataSource.SGRDL)) { numberOfTabs = application.currentReport.getODTabsList().size(); Log.d(TAG, "CURRENT REPORT FROM VIEW PAGER: "+ application.currentReport.toString()); } Log.d(TAG,"Current Tabs number from TabsViewPager activity: " +numberOfTabs); if (application.getCurrentDataSource().equals(DataSource.SSRS)) { for (int i = 0; i < numberOfTabs; i++) { Tab tempTab = application.currentReport.getTabsList().get(i); if (tempTab.getTabTemplateId() == 7) { GridFragment gridFragment = new GridFragment(tempTab); fragments.add(gridFragment); } else if (tempTab.getTabTemplateId() == 8) { NewChartFragment chartFragment = new NewChartFragment(tempTab, this); fragments.add(chartFragment); } } } else if (application.getCurrentDataSource().equals(DataSource.SGRDL)) { for (int i = 0; i < numberOfTabs; i++) { ODTab tempTab = application.currentReport.getODTabsList().get(i); if (tempTab.getTabType().equals(ODGrid.XML_GRID_ELEMENT)) { GridFragment gridFragment = GridFragment.newInstance(tempTab.getTabId()); fragments.add(gridFragment); } else if (tempTab.getTabType().equals(ODChart.XML_CHART_ELEMENT)) { NewChartFragment chartFragment = NewChartFragment.newInstance(tempTab.getTabId()); fragments.add(chartFragment); } } } Log.d(TAG, "Current report fragments set to adapter: "+fragments.toString()); /* if (this.mPagerAdapter == null) { this.mPagerAdapter = new ViewPagerAdapter(super.getSupportFragmentManager(), fragments); } else { this.mPagerAdapter.removeAllFragments(); this.mPagerAdapter.addFragmentsListToAdapter(fragments); } */ this.mPagerAdapter = new ViewPagerAdapter(super.getSupportFragmentManager(), fragments); this.mViewPager = (ViewPager)super.findViewById(R.id.pager); // this.mViewPager.setAdapter(null); this.mViewPager.setAdapter(this.mPagerAdapter); this.mViewPager.setOffscreenPageLimit(0); this.mViewPager.setOnPageChangeListener(this); Log.d(TAG, "Adapter initialized!"); } /** * Initialise the Tab Host */ public void initialiseTabHost(Bundle args) { mTabHost = (TabHost)findViewById(android.R.id.tabhost); /* //new edit if (mTabHost.getChildCount() > 0) { mTabHost.removeAllViews(); } */ mTabHost.setup(); TabInfo tabInfo = null; mapTabInfo = new HashMap<String, TabsViewPagerFragmentActivity.TabInfo>(); if (args != null) {} else { if (application.getCurrentDataSource().equals(DataSource.SSRS)) { int numberOfTabs = application.currentReport.getTabsList().size(); for (int i = 0; i < numberOfTabs; i++) { Tab tempTab = application.currentReport.getTabsList().get(i); if (tempTab.getTabTemplateId() == 7) { //GridFragment gridFragment = new GridFragment(tempTab); TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab "+String.valueOf(i)).setIndicator("Tab "+String.valueOf(i)), ( tabInfo = new TabInfo("Tab "+String.valueOf(i), GridFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); } else if (tempTab.getTabTemplateId() == 8) { TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab "+String.valueOf(i)).setIndicator("Tab "+String.valueOf(i)), ( tabInfo = new TabInfo("Tab "+String.valueOf(i), NewChartFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); } } } else if (application.getCurrentDataSource().equals(DataSource.SGRDL)) { int numberOfTabs = application.currentReport.getODTabsList().size(); for (int i = 0; i < numberOfTabs; i++) { ODTab tempTab = application.currentReport.getODTabsList().get(i); // Log.d(TAG,"Crashed Tab type: "+ tempTab.getTabType()); if (tempTab.getTabType().equals(ODGrid.XML_GRID_ELEMENT)) { //GridFragment gridFragment = new GridFragment(tempTab); TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab "+String.valueOf(i)).setIndicator("Tab "+String.valueOf(i)), ( tabInfo = new TabInfo("Tab "+String.valueOf(i), GridFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); } else if (tempTab.getTabType().equals(ODChart.XML_CHART_ELEMENT)) { TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab "+String.valueOf(i)).setIndicator("Tab "+String.valueOf(i)), ( tabInfo = new TabInfo("Tab "+String.valueOf(i), NewChartFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); } } } } // Default to first tab //this.onTabChanged("Tab1"); // mTabHost.setOnTabChangedListener(this); } /** * Add Tab content to the Tabhost * @param activity * @param tabHost * @param tabSpec * @param clss * @param args */ private static void AddTab(TabsViewPagerFragmentActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { // Attach a Tab view factory to the spec ImageView indicator = new ImageView(activity.getBaseContext()); indicator.setPadding(10, 10, 10, 10); indicator.setImageResource(R.drawable.tab_select_icon_selector); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(10, 10, 10, 10); indicator.setLayoutParams(lp); tabSpec.setIndicator(indicator); tabSpec.setContent(activity.new TabFactory(activity)); tabHost.addTab(tabSpec); } /** (non-Javadoc) * @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String) */ public void onTabChanged(String tag) { //TabInfo newTab = this.mapTabInfo.get(tag); int pos = this.mTabHost.getCurrentTab(); this.mViewPager.setCurrentItem(pos); } /* (non-Javadoc) * @see android.support.v4.view.ViewPager.OnPageChangeListener#onPageScrolled(int, float, int) */ @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected(int) */ @Override public void onPageSelected(int position) { // TODO Auto-generated method stub this.mTabHost.setCurrentTab(position); } /* (non-Javadoc) * @see android.support.v4.view.ViewPager.OnPageChangeListener#onPageScrollStateChanged(int) */ @Override public void onPageScrollStateChanged(int state) { // TODO Auto-generated method stub } How would one save the state of the TabHost and restore it in onResume? Any help would be very appreciated.

    Read the article

  • How can change my TabHost ?

    - by enricozhang
    I have a tabhost, e.g: final TabHost tabs = getTabHost(); tabs.setup(); TabHost.TabSpec spec = null; spec = tabs.newTabSpec("search"); spec.setContent(new Intent(this, Search.class)); spec.setIndicator("search"); tabs.addTab(spec); in this tabhost is a Intent,and in the activity must change to other activity, question is I hope the other actitivy at same tabhost switch? Can do this?

    Read the article

  • Android - Switching Activities with a Tab Layout

    - by Bill Osuch
    This post is based on the Tab Layout  tutorial on the Android developers site, with some modifications. I wanted to get rid of the icons (they take up too much screen real estate), and modify the fonts on the tabs. First, create a new Android project, with an Activity called TabWidget. Then, create two additional Activities called TabOne and TabTwo. Throw a simple TextView on each one with a message identifying the tab, like this: public class TabTwo extends Activity {  @Override  public void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   TextView tv = new TextView(this);   tv.setText("This is tab 2");   setContentView(tv);  } } And don't forget to add them to your AndroidManifest.xml file: <activity android:name=".TabOne"></activity> <activity android:name=".TabTwo"></activity> Now we'll create the tab layout - open the res/layout/main.xml file and insert the following: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android"  android:id="@android:id/tabhost"  android:layout_width="fill_parent"  android:layout_height="fill_parent">  <LinearLayout   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent">   <TabWidget    android:id="@android:id/tabs"    android:layout_width="fill_parent"    android:layout_height="wrap_content" />   <FrameLayout    android:id="@android:id/tabcontent"             android:layout_width="fill_parent"    android:layout_height="fill_parent" />  </LinearLayout> </TabHost> Finally, we'll create the code needed to populate the TabHost. Make sure your TabWidget class extends TabActivity rather than Activity, and add code to grab the TabHost and create an Intent to launch a new Activity:    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, TabOne.class); Add the first tab to the layout:    // Initialize a TabSpec for each tab and add it to the TabHost    spec = tabHost.newTabSpec("tabOne");      spec.setContent(intent);     spec.setIndicator("Tab One");     tabHost.addTab(spec); It's pretty tall as-is, so we'll shorten it:   // Squish the tab a little bit horizontally   tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 40; But the text is a little small, so let's increase the font size:   // Bump the text size up   LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);   android.widget.TabWidget tw = (android.widget.TabWidget) ll.getChildAt(0);   RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0);   TextView lf = (TextView) rllf.getChildAt(1);   lf.setTextSize(20); Do the same for the second tab, and you wind up with this: @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                 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, TabOne.class);         // Initialize a TabSpec for each tab and add it to the TabHost         spec = tabHost.newTabSpec("tabOne");           spec.setContent(intent);          spec.setIndicator("Tab One");          tabHost.addTab(spec);         // Squish the tab a little bit horizontally         tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 40;         // Bump the text size up         LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);         android.widget.TabWidget tw = (android.widget.TabWidget) ll.getChildAt(0);         RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0);         TextView lf = (TextView) rllf.getChildAt(1);         lf.setTextSize(20);            // Do the same for the other tabs         intent = new Intent().setClass(this, TabTwo.class);         spec = tabHost.newTabSpec("tabTwo");          spec.setContent(intent);          spec.setIndicator("Tab Two");         tabHost.addTab(spec);         tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 40;         RelativeLayout rlrf = (RelativeLayout) tw.getChildAt(1);         TextView rf = (TextView) rlrf.getChildAt(1);         rf.setTextSize(20);            tabHost.setCurrentTab(0);     } Save and fire up the emulator, and you should be able to switch back and forth between your tabs!

    Read the article

  • TabHost Problem in android

    - by sairam333
    when i use the TabActivity in my application it display the error,In below final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("tab1") .setContent(this)); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("tab2") .setContent(this)); tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("tab3") .setContent(this)); In the above code error displayed at final TabHost tabHost = getTabHost(); as the method is undefined.But in sample application they use the same function at it is working.In my application why it is not working.Tell me the solution for it.Thanks in advance.

    Read the article

  • Problem with TabHost UI layout.

    - by Alan B
    What I'm trying to do is create a layout like this: +--------+ Search |EditText| [Button] +--------+ +---------+ |Tab 1 |---------+ | |Tab 2 | |---------+---------+-----------------+ | ListView Item 1 | | ListView Item 2 | | ListView Item 3 | | ListView Item 4 | | ListView Item 5 | | ListView Item 6 | | ListView Item 7 | | ListView Item 8 | | ListView Item 9 | | ListView Item 10 | +-------------------------------------+ So that's a TextView saying 'Search', an EditText and a button. Then below it the tabs - Tab 1 has a ListView, Tab 2 some other stuff. I can get a simple TabHost setup with two tabs working fine but can't get the above to lay out properly. Any hints ? I'd create the UI in the Eclipse designer and check the XML from that, except the designer doesn't work with TabHost. And DroidDraw doesn't seem to know about TabHost.

    Read the article

  • Problem running android HelloTabWidget example - NullPointerException on addTab()

    - by Poindextrose
    I've tried the Tab Layout example, and I've also fixed the few typos in the example (and added all the activities to the manifest). However, when I run it on the emulator I get a NullPointerException on the first line that says tabHost.addTab(spec); So my question, of course, is. What is wrong with the example that would cause this exception? I'm using Eclipse Galileo and set the target package as Android 1.5. So far I've had no other problems with the other examples on the android dev site. package com.example.hellotabwidget; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.widget.TabHost; public class HelloTabWidget extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) throws RuntimeException { super.onCreate(savedInstanceState); setContentView(R.layout.main); 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) //final Context context = getApplicationContext(); intent = new Intent().setClass(this, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); //******** NullPointerException after running this line // Do the same for the other tabs intent = new Intent().setClass(this, AlbumsActivity.class); spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, SongsActivity.class); spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTabByTag("artists"); } } main.xml: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /> </LinearLayout> </TabHost>

    Read the article

  • Issues with Android TabHost Example

    - by kevindtimm
    I have been attempting to implement the 'advanced' tabwidget example from google. But, when it tries to call tabHost.addTab(spec); I get a stack trace from the debugger. Sorry, I don't have the stack trace here, but I'm wondering if others have had this same issue (as this code had a number of typo's and missing information that stopped me from even compiling. Can anyone point me to a corrected/running version of this code? The updated information needed are: <activity android:name=".ArtistsActivity"></activity> <activity android:name=".AlbumsActivity"></activity> <activity android:name=".SongsActivity"></activity>

    Read the article

  • Android TabHost: update tabs from tab's activity

    - by joshuadlillie
    I have a TabActivity and am going to have 3 or 4 tabs. In TabA, I would like to have an ExpandableListView, which will list products. I would like TabC to act as a sort of "shopping cart", probably with a ListView of itself. So, my question is: is there a way to interact with the TabHost from the Activity? I would like to be able to click a button inside of TabA and have it update and switch to TabC. Is this possible? Can I get the Tab's activities call it's parents methods?

    Read the article

  • Android: TabHost

    - by paradroid666
    Hi, I have a question in regards to http://developer.android.com/resources/tutorials/views/hello-tabwidget.html Lots of issues are already discussed but this example only works for me if I in the onCreate() method do NOT use setContentView(R.layout.main); Why is that? What do I have to do if I want to mix a tab layout with other elements? Thanks. paradroid666

    Read the article

  • embedding layout inside each tab? - (each tab has its own activity)

    - by Abhi
    I have started with the HelloTabwidget example and it works fine. Now what I am trying to do is have a layout inside each tab. here is what the code looks like myApp extends TabActivity { TabHost tabHost; onCreate() { setContentView (R.layout.main); tabHost = getTabHost(); TabHost.tabspec spec = tabHost.newTabSpec(..).setIndicator(...). setContent(new Intent().setClass(...)); tabHost.addTab(spec); : } } myTab1Actvity extends Activity { ListView myLV; EditText myET; onCreate() { setcontentView (TAB1_LAYOUT); myLV = findViewById(..); : myLV.setAdapter(aa); myET.setOnKeyListener(....) registerforContextMenu(myLV) } } when I run here is the stack trace ERROR/AndroidRuntime(691): java.lang.NullPointerException ERROR/AndroidRuntime(691): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295) ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) ERROR/AndroidRuntime(691): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295) ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) ERROR/AndroidRuntime(691): at android.view.ViewRoot.handleMessage(ViewRoot.java:1819) ERROR/AndroidRuntime(691): at android.os.Handler.dispatchMessage(Handler.java:99) ERROR/AndroidRuntime(691): at android.os.Looper.loop(Looper.java:123) ERROR/AndroidRuntime(691): at android.app.ActivityThread.main(ActivityThread.java:4363) ERROR/AndroidRuntime(691): at java.lang.reflect.Method.invokeNative(Native Method) ERROR/AndroidRuntime(691): at java.lang.reflect.Method.invoke(Method.java:521) ERROR/AndroidRuntime(691): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) ERROR/AndroidRuntime(691): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) Does the code's flow look OK? basically each Tab has its own activity and each tab has its own layout. It appears that something is wrong in the TabHost - but I am unable to pinpoint it. Any suggestions/Qs you hav e will be very helpful.

    Read the article

  • WebView inside Tab hiding the tabWidgets

    - by brockoli
    I'm having trouble with a WebView always filling the full screen and thus covering my tabs. Here is my code for the tabhost.. public class tabNZBMobile extends TabActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); 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, NewzbinMobile.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("search").setIndicator("Search", res.getDrawable(R.drawable.ic_tab_search)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, sabnzbWeb.class); spec = tabHost.newTabSpec("sabnzbweb").setIndicator("SabNZBd", res.getDrawable(R.drawable.ic_tab_sabnzbweb)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTabByTag("search"); }} My first tab (NewzbinMobile.class) displays correctly, it's just a relativelayout. But my second tab is an activity showing a webview and it is showing, but using the whole screen, covering my tabs. Here is the code for my second tab. public class sabnzbWeb extends Activity { WebView mWebView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String sabNZBurl = new String("http://test.server.org:8080/m"); mWebView = new WebView(this); mWebView.getSettings().setJavaScriptEnabled(true); setContentView(mWebView); mWebView.loadUrl(sabNZBurl); }}

    Read the article

  • how to send the values from TabActivity to Activity?

    - by Anil M H
    In my TabActivity , i'm sending value to other Activity how to do that in this TabActivity how can i send the bundle to other Activity plz tell me how to pass the value to my other ReceivedList Activity plz tell me .... public class TabViewForSendAndRecv extends TabActivity{ private TabActivity tabhost1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tabviewforsendandrecv); Bundle bundle = getIntent().getExtras(); String stuff = bundle.getString("number"); final TabHost tabHost = getTabHost(); TextView txtTab = new TextView(this); txtTab.setText("Received Alerts"); txtTab.setPadding(8, 9, 8, 9); txtTab.setTextColor(Color.WHITE); txtTab.setTextSize(14); //txtTab.setTypeface(localTypeface1); txtTab.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); TabHost.TabSpec spec; // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("Tab1").setIndicator(txtTab). setContent(new Intent(this, ReceivedList.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); tabHost.addTab(spec); //tab 2 TextView txtTab1 = new TextView(this); txtTab1.setText("Sent Alerts"); txtTab1.setPadding(8, 9, 8, 9); txtTab1.setTextColor(Color.WHITE); txtTab1.setTextSize(14); //txtTab.setTypeface(localTypeface1); txtTab1.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); TabHost.TabSpec spec1; // Initialize a TabSpec for each tab and add it to the TabHost spec1 = tabHost.newTabSpec("Tab2").setIndicator(txtTab1).setContent(new Intent(this, SentList.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); tabHost.addTab(spec1);

    Read the article

  • Android: TabHost How To: set new content in existing tabs upon menu button?

    - by Martin D.
    Hello stackoverflow, I recently started Android programming and was working on my first program which displays a historic text document, sectioned by tabs via TabHost. I have limited my program to one activity and merely used setContent in my TabSpec's to switch between different XML views. The document has both unedited and corrected versions of the text for which I have built text views to accommodate. I wanted to implement the standard menu to have buttons to "view corrected" and "view original" and switch the content of the tabs which have changes (without altering the tabs or their indicators). I've read on the TabHost API and there is no way to edit existing tab content with setContent() of TabSpec; and AFAIK TabWidget only affects the actual tabs, not the content that is displayed upon pressing them. I've thought about creating a new class which extended TabHost and super() all of the original methods, while including one more which updated the mTabSpec list. My question would be, how would I update the frameLayout view of a specific tab to display content I specify?

    Read the article

  • Android on TabHost little more depth of the problem, there is the hard return key on the treatment.

    - by user365723
    Hello everybody, I have a question on the Android Activity, for example I have a TabHost, and there are included four Activities, the first tab is a search Activity, enter a keyword in the current result of this Activity to return, and in the current Activity display. Is called to display the search results themselves. And after searching several times, and then return to key mobile phone keypad, the display is the result of the last search keyword, I want the press back key to return to the last call of the Activity or TabHost. Should I do? By the way, in a tab in the use of Intent calls a Activity, eg: host.addTab (host.newTabSpec ("friend"). setIndicator ("search") . SetContent (new Intent (this, Search.class))); In this Activity in the need to call another Activity, e.g: startActivity (new Intent (this, Other.class)); Also called another Activity displayed on this tab, but not yet jump out of the show. I ask how you can achieve this?

    Read the article

  • How to startactivityforresult in tab child of TabHost

    - by user541383
    I have TabHost with tab child like this: tabHost.addTab(tabHost.newTabSpec("web") .setIndicator("web") .setContent(new Intent(this, webview.class))); In WebView class, I startactivityforresult: startActivityForResult(new Intent(Webview.this,EventManage.class),GET_CODE); In Eventmanage class, I set result but can not capture result in webview class. Anybody can help me with this problem?

    Read the article

  • TabHost NullPointerException in layout

    - by Chubbs
    I been following the Tab example provided by Google. I am trying to use the XML layout provided to setup a tab layout. I use this XML layout @ http://developer.android.com/guide/tutorials/views/hello-tabwidget.html <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is a tab" /> <TextView android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is another tab" /> <TextView android:id="@+id/textview3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is a third tab" /> </FrameLayout> </LinearLayout> </TabHost> When ever I switch the Layout tab in the Eclipse layout designer I get a NullPointerException: null error inside my Eclipse. This happens also when I try to drag and drop a TabHost, and then a TabWidget into an empty layout file. What am I doing wrong ? this seems pretty simple.

    Read the article

  • How can I switch the activity of the content of a tab in Tabhost

    - by hap497
    Hi, I have created a TabHost and in 1 of the tab, I have added the content using mTabHost.addTab(mTabHost.newTabSpec("tab1") .setIndicator(getString(R.string.dialerIconLabel), getResources().getDrawable(R.drawable.ic_tab_dialer)) .setContent(intent)); Is it possible for me to switch the content's activity programatically after I called 'addTab of TabHost'? Thank you.

    Read the article

  • TextBox Inside TabHost isn't clickable

    - by agam360
    Here is my code:(main.xml -layout) <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <MultiAutoCompleteTextView android:id="@+id/txtCode" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.25" android:capitalize="none" android:focusable="true" android:focusableInTouchMode="false" android:gravity="top|left" android:text="@string/strtxtCode" android:textSize="26dp" android:textStyle="bold" android:typeface="normal" /> <MultiAutoCompleteTextView android:id="@+id/txtCodeHTML" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.25" android:capitalize="none" android:focusable="true" android:focusableInTouchMode="false" android:gravity="top|left" android:text="@string/strtxtCode2" android:textSize="26dp" android:textStyle="bold" android:typeface="normal" /> </FrameLayout> </LinearLayout> </TabHost> When I try to click(touch) the text-box, it does nothing. What should I do in order to fix this?

    Read the article

  • Android ActivityGroup

    - by Vahag Vardanyan
    I know that ActivityGroup is in the "past", but I want to learn how to use it. So I write a simple TabHost, and want to show different activities using ActivityGroup. Here are the parts of code Player.java package player.org; import android.app.Activity; import android.app.TabActivity; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.media.MediaPlayer; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ProgressBar; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TabHost; import android.widget.TabWidget; import android.widget.TextView; public class Player extends TabActivity { /** Called when the activity is first created. */ private MediaPlayer media=null; private SeekBar progress; private View play; private Progress p; TabHost tabhost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tabs); Resources res=getResources(); //TabHost tabhost=(TabHost) findViewById(R.id.tabhost); // tabhost.setup(); tabhost=getTabHost(); TabHost.TabSpec spec; Intent intent; intent=new Intent(this,Progress.class); spec=tabhost.newTabSpec("now playing").setIndicator("Now playing", res.getDrawable(R.drawable.icon)) .setContent(intent); tabhost.addTab(spec); intent=new Intent(this,Group.class); spec=tabhost.newTabSpec("all_songs").setIndicator("All songs", res.getDrawable(R.drawable.songs)) .setContent(intent); tabhost.addTab(spec); //intent=new Intent(this,Progress.class); spec=tabhost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.icon)) .setContent(intent); tabhost.addTab(spec); spec=tabhost.newTabSpec("alboom").setIndicator("Alboom", res.getDrawable(R.drawable.icon)) .setContent(intent); tabhost.addTab(spec); tabhost.setCurrentTab(0); } } Group.java import android.os.Bundle; import android.view.View; public class Group extends ActivityGroup { @Override public void onCreate(Bundle savedInstanceStated) { super.onCreate(savedInstanceStated); View view = getLocalActivityManager().startActivity("AllSongs", new Intent(this, AllSongs.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); setContentView(view); } AllSongs.java package player.org; import java.util.ArrayList; import android.R.id; import android.app.ActivityGroup; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TabHost; public class AllSongs extends ListActivity{ ArrayList<String> listItem=new ArrayList<String>(); ArrayAdapter<String> adapter; ListView listView; //Player p; TabHost tab; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //p=new Player(); adapter=new ArrayAdapter<String>(this,R.layout.list_item,listItem); setListAdapter(adapter); listView=getListView(); listView.setTextFilterEnabled(true); listView.setOnItemClickListener(listener); addItem("vahag"); addItem("vahagvahag"); } private OnItemClickListener listener=new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Intent intent = new Intent(AllSongs.this,Progress.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Group group= (Group) getParent(); View view=group.getLocalActivityManager().startActivity("Progress",intent).getDecorView(); setContentView(view); } }; public void addItem(String s) { listItem.add(s); adapter.notifyDataSetChanged(); } } and the Progress.java package player.org; import android.app.Activity; import android.app.ActivityGroup; import android.app.Dialog; import android.app.TabActivity; import android.content.Context; public class Progress extends Activity { // Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } So, AllSongs.java try to change current activity with Progress activity, but when I press on list item, the Programm forsed closed, and logChat says "08-17 12:49:26.471: ERROR/AndroidRuntime(1500): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'" I can't figure how to fix this problem, Can anyone helps?

    Read the article

  • Modify tab indicator dynamically in Android

    - by ZelluX
    My application needs to update tab indicator dynamically, I'm trying to do this by invoke TabSpec.setIndicator(), but it doesn't work. Here is my code: In onCreate method of TabActivity: tabHost = getTabHost(); TabSpec tabSpec = tabHost.newTabSpec("abc"); tabSpec.setIndicator("helloabc"); tabSpec.setContent(new MyViewFactory()); tabHost.addTab(tabSpec); Now I need to change tab indicator to another string, for example, "xyz" TabSpec tabSpec = MyTabActivity.getTabSpec(); tabSpec.setIndicator("xyz"); But it doesn't work. So I'd like to know how to change tab indicator after it is added to the tabhost? Many thanks.

    Read the article

1 2 3 4 5  | Next Page >