Solved

tab example

Posted on 2012-03-26
10
352 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now