0

I have followed this tutorial (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) and completed the task and it all works fine.

However now I am not sure how can I add diffrent layouts under each tabs? should add the layout to the main.xml and somehow call the layout from the calasses I have created for each tabs?

I would highly appreciate if can someone advice me on that.

For example I want to add a table layout under one of the tabs, how can I do that?

Many thanks

NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
Zardaloop
  • 1,594
  • 5
  • 22
  • 43

1 Answers1

0

See This example it is usefull Example of the TabLayout

modified this class Androidactivity.java

public class AndroidActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.androidtab);

add this xml file in Res/layout/androidtab.xml

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"    
android:layout_width="fill_parent"
android:layout_height="fill_parent"       
android:gravity="top"       
android:stretchColumns="1">
<LinearLayout
    android:id="@+id/top_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/text"
        android:textStyle="bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="20dp"
        android:text="Create Photo" />
</LinearLayout>    
 <TextView            
        android:id="@+id/editUsername"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_weight="4"
        android:text="CREATE NEW RECORD"            
        android:layout_marginLeft="25dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="75dp"   
        android:textStyle="bold"
        android:padding="10dp"/>
<TableLayout  
      android:id="@+id/tableLayout1"    
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"       
      android:gravity="top"       
      android:stretchColumns="1">       
  <TableRow
       android:id="@+id/row2"
       android:layout_marginTop="45dp"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">
    <EditText
        android:inputType="text"
        android:id="@+id/editUsername"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_weight="2"
        android:singleLine="true"
        android:hint="input field1"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="2dip"
        android:layout_marginRight="75dp"   
        android:padding="10dp"/>
</TableRow>
<TableRow
    android:id="@+id/row2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <EditText
        android:inputType="text"
        android:id="@+id/editUsername"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_weight="2"
        android:singleLine="true"
        android:hint="input field2"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="2dip"
        android:layout_marginRight="75dp"   
        android:padding="10dp"/>
</TableRow>             
  <TableRow
    android:id="@+id/row2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <EditText
        android:inputType="text"
        android:id="@+id/editUsername"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_weight="2"
        android:singleLine="true"
        android:hint="input field3"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="2dip"
        android:layout_marginRight="75dp"   
        android:padding="10dp"/>
</TableRow>    
  <TableRow
    android:id="@+id/row2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <EditText
        android:inputType="text"
        android:id="@+id/editUsername"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_weight="2"
        android:singleLine="true"
        android:hint="input field4"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="2dip"
        android:layout_marginRight="75dp"   
        android:padding="10dp"/>
</TableRow>
  <RelativeLayout
      android:id="@+id/linearlayout"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:orientation="horizontal" 
      android:gravity="bottom" >
       <Button
        android:id="@+id/takephoto"
        android:layout_width="110dp"
        android:layout_height="35dp"
        android:text="takephoto"                   
        android:textStyle="bold"
        android:layout_marginLeft="102dp"    />
  </RelativeLayout>

NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
  • Thanks @NagarjunaReddy but this one only has a text, in each tab, I have had a look at this one, but none of these examples explain how to use layouts under each tab, for example, instead of a text I want to have a table layout. – Zardaloop May 30 '12 at 08:53
  • Add layout to the classes you have created for each tab.Tabs will be visible in each activity. – AndroidLearner May 30 '12 at 09:03
  • @ shubhangi many thanks for your reply, could you pleas give me a simple example of how to add layout to the class? I only know how to use layouts in xml files, not sure how to use layout within the class? – Zardaloop May 30 '12 at 09:37
  • @ NagarjunaReddy could you please give me a simple line of code to how to add layout in the class? or maybe direct me to asimilatr example? Many thanks – Zardaloop May 30 '12 at 09:39
  • @user1163454 hi first download that code and see my edit code – NagarjunaReddy May 30 '12 at 09:59
  • @ NagarjunaReddy, once again thanks. But unfrotunately that method didn't solve my quesiton, that could be because I didn't maybe fully undrestand that. But this post have perfectly answred my question : http://stackoverflow.com/questions/2576661/how-to-add-controls-to-a-tab-layout-in-android – Zardaloop May 30 '12 at 18:18