Regarding Tabhost

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Regarding Tabhost

Postby ashoka » Fri Apr 18, 2008 1:37 pm

In my application,i'd like to create multiple tabs.For example i've button..after clicking that button it should create one more tab,likewise i've to create multiple tabs with same button(just like mozilla browser)..i've plan to use button in the first page.Is it possible to use?..If it's possible please send me some codings..

Regards,
Ashok...
ashoka
Freshman
Freshman
 
Posts: 6
Joined: Tue Apr 01, 2008 11:30 am

Top

Postby faldureon » Sun Apr 20, 2008 8:52 pm

Here is how I use the TabHost widget in my project - Geocast:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public void onCreate(Bundle icicle) {
  3.                 super.onCreate(icicle);
  4.  
  5.                 // some init code, nothing to do with TabHost useage
  6.                 GeocastContainer.setParentActivity(Geocast.this);
  7.                 handler = new Handler();
  8.                 playShareableButtonHeight = getResources().getDrawable(
  9.                                 R.drawable.playshareableicon).getIntrinsicHeight();
  10.                 playShareableButtonWidth = getResources().getDrawable(
  11.                                 R.drawable.playshareableicon).getIntrinsicWidth();
  12.  
  13.                 // the geocast options tab view is initialised
  14.                 final View geocastOptionsTabView = new GeocastOptionsTabView(this);
  15.                 geocastOptionsTabView.setLayoutParams(new FrameLayout.LayoutParams(
  16.                                 LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  17.  
  18.                 // construct the tabhost
  19.                 tabHost = new TabHost(this);
  20.                 tabHost.setLayoutParams(new LinearLayout.LayoutParams(
  21.                                 LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  22.  
  23.                 // every tabhost needs a tabwidget - a container for the clickable tabs
  24.                 // up top. The id is important!
  25.                 TabWidget tabWidget = new TabWidget(this);
  26.                 tabWidget.setId(android.R.id.tabs);
  27.                 tabHost.addView(tabWidget, new LinearLayout.LayoutParams(
  28.                                 LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  29.  
  30.                 // every tabhost needs a frame layout for the views associated with each
  31.                 // clickable tab. The id is important!
  32.                 FrameLayout frameLayout = new FrameLayout(this);
  33.                 frameLayout.setId(android.R.id.tabcontent);
  34.                 frameLayout.setPadding(0, 65, 0, 0);
  35.                 tabHost.addView(frameLayout, new LinearLayout.LayoutParams(
  36.                                 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  37.  
  38.                 // setup must be called if you are not initialising the tabhost from XML
  39.                 tabHost.setup();
  40.  
  41.                 // a tabhost is populated with tabspec objects. Each tabspec consists of
  42.                 // an indicator(the clickable tab on the top), and content(the view
  43.                 // displayed when an indicator is clicked)
  44.                 TabSpec tabSpec = tabHost.newTabSpec("Shareable List");
  45.                 tabSpec.setIndicator("Shareable List");
  46.                 tabSpec.setContent(new TabContentFactory() {
  47.  
  48.                         @Override
  49.                         public View createTabContent(String arg0) {
  50.                                 if (shareableListTabView == null) {
  51.                                         shareableListTabView = new ShareableListTabView(
  52.                                                         Geocast.this);
  53.                                 }
  54.                                 return shareableListTabView;
  55.                         }
  56.                 });
  57.                 tabHost.addTab(tabSpec);
  58.  
  59.                 tabSpec = tabHost.newTabSpec("Geocast Options");
  60.                 tabSpec.setIndicator("Geocast Options");
  61.                 tabSpec.setContent(new TabContentFactory() {
  62.  
  63.                         @Override
  64.                         public View createTabContent(String arg0) {
  65.                                 return geocastOptionsTabView;
  66.                         }
  67.                 });
  68.                 tabHost.addTab(tabSpec);
  69.  
  70.                 shareableMapTabView = new ShareableMapTabView(Geocast.this);
  71.                 tabSpec = tabHost.newTabSpec("Shareable Map");
  72.                 tabSpec.setIndicator("Shareable Map");
  73.                 tabSpec.setContent(new TabContentFactory() {
  74.  
  75.                         @Override
  76.                         public View createTabContent(String arg0) {
  77.                                 return shareableMapTabView;
  78.                         }
  79.                 });
  80.                 tabHost.addTab(tabSpec);
  81.  
  82.                 initUploadShareableOptionsLayout();
  83.                 tabSpec = tabHost.newTabSpec("Create Shareables");
  84.                 tabSpec.setIndicator("Create Shareables");
  85.                 tabSpec.setContent(new TabContentFactory() {
  86.  
  87.                         @Override
  88.                         public View createTabContent(String arg0) {
  89.                                 return uploadShareablesOptionsLayout;
  90.                         }
  91.                 });
  92.                 tabHost.addTab(tabSpec);
  93.  
  94.                 DownloadedDataContainer.getInstance()
  95.                                 .addDownloadedDataContainerListener(this);
  96.  
  97.                 // you can use setcurrenttab to select a tab in the tabhost
  98.                 // programmatically
  99.                 if (icicle != null && icicle.containsKey("tabindex")) {
  100.                         tabHost.setCurrentTab(icicle.getInt("tabindex"));
  101.                 } else {
  102.                         tabHost.setCurrentTab(1);
  103.                 }
  104.  
  105.                 // this gets called whenever the tab selection is changed
  106.                 // programmatically, or by the user
  107.                 tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
  108.  
  109.                         @Override
  110.                         public void onTabChanged(String arg0) {
  111.                                 selectedTab = tabHost.getCurrentTab();
  112.                                 refreshOpenTab();
  113.                         }
  114.                 });
  115.  
  116.                 // a hacky way of setting the font of the indicator texts
  117.                 for (int i = 0; i < tabWidget.getChildCount(); i++) {
  118.                         if (tabWidget.getChildAt(i) instanceof RelativeLayout) {
  119.                                 RelativeLayout relativeLayout = (RelativeLayout) tabWidget
  120.                                                 .getChildAt(i);
  121.                                 for (int j = 0; j < relativeLayout.getChildCount(); j++) {
  122.                                         if (relativeLayout.getChildAt(j) instanceof TextView) {
  123.                                                 ((TextView) relativeLayout.getChildAt(j))
  124.                                                                 .setTextSize(GeocastContainer.getInstance()
  125.                                                                                 .getGlobalFontSize());
  126.                                         }
  127.                                 }
  128.  
  129.                         }
  130.                 }
  131.  
  132.                 setContentView(tabHost);
  133.         }
  134.  
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


This code results in a tabhost like this:
Image
faldureon
Developer
Developer
 
Posts: 27
Joined: Sun Dec 02, 2007 10:19 pm

Postby JoyLakh » Mon Mar 02, 2009 12:02 pm

Thanks mate.
Celebrate Life.
JoyLakh
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Dec 16, 2008 5:42 am
Location: Bangalore, India

Need help in Getting the Message count

Postby damu » Wed Aug 19, 2009 11:06 am

Hi

in the android i need to calculate the outgoing (Sent) message count in between the given date to today date how can i get i tried to get from the log but if i clear the the log i can not bale to get please help me to find the solution

Thank You
damu.be@gmail.com
Thank you

Damu
damu
Freshman
Freshman
 
Posts: 5
Joined: Thu Aug 13, 2009 10:37 am
Location: tirunelveli

Re: Regarding Tabhost

Postby Andriy Stefanov » Mon Oct 11, 2010 11:24 pm

Thank you very very much!!! I've searched for this for sooooooo long
Andriy Stefanov
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Oct 11, 2010 11:23 pm

Top

Return to General

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests