contoh koding pembuatan tabhost di eclipse
<?xml
version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_x="0dp"
android:layout_y="0dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/dody"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView1"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="SI12B"/>
</LinearLayout>
<LinearLayout
android:id="@+id/noer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView2"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="12.12.0069"/>
</LinearLayout>
<LinearLayout
android:id="@+id/rahim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView3"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="AMIKOM"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</AbsoluteLayout>
</LinearLayout>
1.
Setelah itu buka MainActivity.java, lalu ketikan
coding berikut:
package com.Joo.tabhost;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec
spec1=tabHost.newTabSpec("SI12B");
spec1.setContent(R.id.dody);
spec1.setIndicator("DODY");
TabSpec
spec2=tabHost.newTabSpec("12.12.0069");
spec2.setIndicator("NOER");
spec2.setContent(R.id.noer);
TabSpec
spec3=tabHost.newTabSpec("AMIKOM");
spec3.setContent(R.id.rahim);
spec3.setIndicator("RAHIM");
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
}
}
Tidak ada komentar:
Posting Komentar