Solved

tab example

Posted on 2012-03-26
10
360 Views
Last Modified: 2012-03-26
I am after a simple tab example with android.

THis example had a whole lot of brackets which appears to be wrong.

http://som-itsolutions.blogspot.com.au/2009/10/tabs-in-android-through-example.html
0
Comment
Question by:jagguy
  • 6
  • 3
10 Comments
 

Author Comment

by:jagguy
ID: 37765680
I tried this and it works except for the text appears in the tab  eg this is tab1

http://www.codeproject.com/Articles/107693/Tabbed-Applications-in-Android
0
 
LVL 7

Expert Comment

by:gudii9
ID: 37766160
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37768753
This one
http://som-itsolutions.blogspot.com.au/2009/10/tabs-in-android-through-example.html

is working for me - clocks a little bit misplaced but otherwise OK

I just need to change parenthesees in main.xml to "<" and ">" like in normal XML (sse below)
Java code in activity pasted as it is:

package com.example4;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;

public class TabExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

TabHost tabs = (TabHost)findViewById(R.id.TabHost01);

tabs.setup();

TabHost.TabSpec spec1 = tabs.newTabSpec("tag1");

spec1.setContent(R.id.AnalogClock01);
spec1.setIndicator("Analog Clock");

tabs.addTab(spec1);

TabHost.TabSpec spec2 = tabs.newTabSpec("tag2");
spec2.setContent(R.id.DigitalClock01);
spec2.setIndicator("Digital Clock");

tabs.addTab(spec2);
}
}

Open in new window


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<TabHost android:id="@+id/TabHost01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TabWidget android:id="@android:id/tabs" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="65px">
<AnalogClock android:id="@+id/AnalogClock01" android:layout_width="wrap_content" android:layout_height="wrap_content"></AnalogClock>
<DigitalClock android:text="DigitalClock01" android:id="@+id/DigitalClock01" android:layout_width="wrap_content" android:layout_height="wrap_content"></DigitalClock>
</FrameLayout>
</TabHost>
</LinearLayout>

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 47

Expert Comment

by:for_yan
ID: 37768804
This is how it looks:

andr-analog
andr-digi
0
 

Author Comment

by:jagguy
ID: 37768814
With this code I get the tab displaying messages in the tab itself by mistake. How do I fix this?
See the file attached


<?xml version="1.0" encoding="utf-8"?>
  <TabHost android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tabHost"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <TabWidget
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/tabs"
    />
     <FrameLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@android:id/tabcontent"
     >
     <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tab1"
    android:orientation="vertical"
    android:paddingTop="60px"
     >
     <TextView  
    android:layout_width="fill_parent"
    android:layout_height="100px"
    android:text="This is tab1"
    android:id="@+id/txt1"
    />    
   
     </LinearLayout>
     
     <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab2"
    android:orientation="vertical"
    android:paddingTop="60px"
     >
     <TextView  
    android:layout_width="fill_parent"
    android:layout_height="100px"
    android:text="not tab 2"
    android:id="@+id/txt2"
    />
   
     </LinearLayout>
     
      <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab3"
    android:orientation="vertical"
    android:paddingTop="60px"
     >
     <TextView  
    android:layout_width="fill_parent"
    android:layout_height="100px"
    android:text="This is tab 3"
    android:id="@+id/txt3"
    />
   
     </LinearLayout>
     </FrameLayout>
   
    </TabHost>
tab.docx
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37768943
I changed all theree

  android:paddingTop="60px"
to

  android:paddingTop="120px"

and it looks much better

<?xml version="1.0" encoding="utf-8"?>

    <TabHost android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tabHost"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <TabWidget
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/tabs"
    />
     <FrameLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@android:id/tabcontent"
     >
     <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tab1"
    android:orientation="vertical"
    android:paddingTop="120px"
     >
     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    android:text="This is tab1"
    android:id="@+id/txt1"
    />    
    
     </LinearLayout>
     
     <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab2"
    android:orientation="vertical"
    android:paddingTop="120px"
     >
     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    android:text="This is tab 2"
    android:id="@+id/txt2"
    />
   
     </LinearLayout>
     
      <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab3"
    android:orientation="vertical"
    android:paddingTop="120px"
     >
     <TextView  
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    android:text="This is tab 3"
    android:id="@+id/txt3"
    />
   
     </LinearLayout>
     </FrameLayout>
    
    </TabHost>

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37768954
moved to 120 px
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37768964
Did you try to transfer any of these to a real phone ?
0
 

Author Comment

by:jagguy
ID: 37769029
Thanks for the above solution.

OK I since moved onto this example given below.This is more suited to what I want. However it isnt working as I get force to close.

http://www.androidpeople.com/android-tabhost-tutorial-part-1


This works as well providing I dont foget to extend TabActivity

public class Tab2Activity extends TabActivity {
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 37769078
If you download the full code form the bottom of that link
http://www.androidpeople.com/wp-content/uploads/2010/07/TabBar1.zip
you;ll see that they still have main.xml  in the zip file:


<?xml version="1.0" encoding="utf-8" ?> 
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
  <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> 
  </LinearLayout

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question