Langsung ke konten utama

Widget: TabHost (buat Tab BARU)

Buat Layout
<?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: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" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >


            <RelativeLayout                
                android:id="@+id/tab2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="top" >

                <TextView
                    android:id="@+id/label"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Type here:" />

                <EditText
                    android:id="@+id/entry"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/label" />

                <Button
                    android:id="@+id/ok"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_below="@id/entry"
                    android:layout_marginLeft="10dip"
                    android:text="OK" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignTop="@id/ok"
                    android:layout_below="@+id/entry"
                    android:layout_toLeftOf="@+id/ok"
                    android:text="Cancel" />
            </RelativeLayout>
        </FrameLayout>
    </LinearLayout>

</TabHost>


Buat Java
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();

TabSpec tLinear = tabHost.newTabSpec("LinearLayout");
tLinear.setIndicator("Linear");
Intent acLinear = new Intent(MainActivity.this, LinearActivity.class);
tLinear.setContent(acLinear);
tabHost.addTab(tLinear);

TabSpec tRelative = tabHost.newTabSpec("RelativeLayout");
tRelative.setIndicator("Relative");
Intent acRelative = new Intent(MainActivity.this, RelativeActivity.class);
tRelative.setContent(acRelative);
tabHost.addTab(tRelative);

TabSpec tTable = tabHost.newTabSpec("TableLayout");
tTable.setIndicator("Table");
Intent acTable = new Intent(MainActivity.this, TableActivity.class);
tTable.setContent(acTable);
tabHost.addTab(tTable);

TabSpec tabSpec2 = tabHost.newTabSpec("baru");
tabSpec2.setIndicator("BARU");
tabSpec2.setContent(R.id.tab2);
tabHost.addTab(tabSpec2);

}
}

Komentar

Postingan populer dari blog ini

Menampilkan Data MySQL

Web Service: getAccount.php <?php include "connect_db.php"; $query = "SELECT username,password FROM tbaccount"; $result = mysql_query($query, $link) or die('Errorquery:  '.$query); $rows = array(); while ($r = mysql_fetch_assoc($result)) {     $rows[] = $r; } $data = "{Account:".json_encode($rows)."}"; echo $data; ?> Layout Adapter <? xml version= "1.0" encoding= "utf-8" ?> < LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android :layout_width= "fill_parent" android :layout_height= "fill_parent" android :orientation= "vertical" > < LinearLayout android :layout_width= "fill_parent" android :layout_height= "fill_parent" android :layout_weight= "1" android :orientation= "horizontal" > < TextView android...