Senin, 09 Oktober 2017
Senin, 02 Oktober 2017
Materi SetOnClickListener
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener{
Button keluar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
keluar = (Button) findViewById(R.id.exitBtn1);
keluar.setOnClickListener(this);
Button linearLayout = (Button) findViewById(R.id.ButtonLinear);
linearLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View linear) {
Intent myIntent = new Intent(linear.getContext(),
LinearActivity.class);
startActivityForResult(myIntent, 0);
}
});
Button relativeLayout = (Button) findViewById(R.id.ButtonRelative);
relativeLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View relative) {
Intent myIntent = new Intent(relative.getContext(),
RelativeActivity.class);
startActivityForResult(myIntent, 0);
}
});
Button tableLayout = (Button) findViewById(R.id.ButtonTable);
tableLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View table) {
Intent myIntent = new Intent(table.getContext(),
TableActivity.class);
startActivityForResult(myIntent, 0);
}
});
}
public void onClick(View clicked) {
switch (clicked.getId()) {
case R.id.exitBtn1: exit(); break;
}
}
private void exit() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah Kamu Benar-Benar ingin keluar?")
.setCancelable(false)
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.this.finish();
}
})
.setNegativeButton("Tidak",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int arg1) {
dialog.cancel();
}
}).show();
}
}
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener{
Button keluar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
keluar = (Button) findViewById(R.id.exitBtn1);
keluar.setOnClickListener(this);
Button linearLayout = (Button) findViewById(R.id.ButtonLinear);
linearLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View linear) {
Intent myIntent = new Intent(linear.getContext(),
LinearActivity.class);
startActivityForResult(myIntent, 0);
}
});
Button relativeLayout = (Button) findViewById(R.id.ButtonRelative);
relativeLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View relative) {
Intent myIntent = new Intent(relative.getContext(),
RelativeActivity.class);
startActivityForResult(myIntent, 0);
}
});
Button tableLayout = (Button) findViewById(R.id.ButtonTable);
tableLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View table) {
Intent myIntent = new Intent(table.getContext(),
TableActivity.class);
startActivityForResult(myIntent, 0);
}
});
}
public void onClick(View clicked) {
switch (clicked.getId()) {
case R.id.exitBtn1: exit(); break;
}
}
private void exit() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Apakah Kamu Benar-Benar ingin keluar?")
.setCancelable(false)
.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainActivity.this.finish();
}
})
.setNegativeButton("Tidak",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int arg1) {
dialog.cancel();
}
}).show();
}
}
Sabtu, 30 September 2017
Jumat, 29 September 2017
TabHost 4 (Panggil CheckBox & RadioButton)
Buat Class 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>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pilihlah tipe kopi yang anda suka" >
</TextView>
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="luwak" >
</RadioButton>
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ekspresso" >
</RadioButton>
<RadioButton
android:id="@+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="colombian" >
</RadioButton>
</RadioGroup>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="apa yang ingin anda tambahkan" >
</TextView>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gula" >
</CheckBox>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="kopi" >
</CheckBox>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" >
</Button>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" >
</TextView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
Buat Class Java
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class MainActivity extends TabActivity {
RadioGroup rg1;
RadioButton rb1, rb2, rb3;
CheckBox cb1, cb2;
Button b1;
TextView t1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
rg1 = (RadioGroup) findViewById(R.id.radioGroup1);
rb1 = (RadioButton) findViewById(R.id.radio1);
rb2 = (RadioButton) findViewById(R.id.radio2);
rb3 = (RadioButton) findViewById(R.id.radio3);
cb1 = (CheckBox) findViewById(R.id.checkBox1);
cb2 = (CheckBox) findViewById(R.id.checkBox2);
b1 = (Button) findViewById(R.id.button1);
t1 = (TextView) findViewById(R.id.textView3);
b1.setOnClickListener(new klik());
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);
TabSpec tabSpec3 = tabHost.newTabSpec("Check-Radio");
tabSpec3.setIndicator("CHECK-RADIO");
tabSpec3.setContent(R.id.tab3);
tabHost.addTab(tabSpec3);
}
class klik implements OnClickListener{
public void onClick(View v){
t1.setText(" ");
String msg1 = "", msg2 = "";
if(rb1.isChecked())
msg1 = msg1 + "luwak";
if(rb2.isChecked())
msg1 = msg1 + "ekspresso";
if(rb3.isChecked())
msg1 = msg1 + "colombian";
t1.append("kopi yang anda pilih: "+msg1);
if(cb1.isChecked())
msg2 = msg2 + " gula";
if(cb2.isChecked())
msg2 = msg2 + " kopi";
t1.append(" dan yang anda tambahkan adalah"+msg2);
}
}
}
<?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>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pilihlah tipe kopi yang anda suka" >
</TextView>
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="luwak" >
</RadioButton>
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ekspresso" >
</RadioButton>
<RadioButton
android:id="@+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="colombian" >
</RadioButton>
</RadioGroup>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="apa yang ingin anda tambahkan" >
</TextView>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gula" >
</CheckBox>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="kopi" >
</CheckBox>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" >
</Button>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" >
</TextView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
Buat Class Java
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class MainActivity extends TabActivity {
RadioGroup rg1;
RadioButton rb1, rb2, rb3;
CheckBox cb1, cb2;
Button b1;
TextView t1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
rg1 = (RadioGroup) findViewById(R.id.radioGroup1);
rb1 = (RadioButton) findViewById(R.id.radio1);
rb2 = (RadioButton) findViewById(R.id.radio2);
rb3 = (RadioButton) findViewById(R.id.radio3);
cb1 = (CheckBox) findViewById(R.id.checkBox1);
cb2 = (CheckBox) findViewById(R.id.checkBox2);
b1 = (Button) findViewById(R.id.button1);
t1 = (TextView) findViewById(R.id.textView3);
b1.setOnClickListener(new klik());
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);
TabSpec tabSpec3 = tabHost.newTabSpec("Check-Radio");
tabSpec3.setIndicator("CHECK-RADIO");
tabSpec3.setContent(R.id.tab3);
tabHost.addTab(tabSpec3);
}
class klik implements OnClickListener{
public void onClick(View v){
t1.setText(" ");
String msg1 = "", msg2 = "";
if(rb1.isChecked())
msg1 = msg1 + "luwak";
if(rb2.isChecked())
msg1 = msg1 + "ekspresso";
if(rb3.isChecked())
msg1 = msg1 + "colombian";
t1.append("kopi yang anda pilih: "+msg1);
if(cb1.isChecked())
msg2 = msg2 + " gula";
if(cb2.isChecked())
msg2 = msg2 + " kopi";
t1.append(" dan yang anda tambahkan adalah"+msg2);
}
}
}
Senin, 25 September 2017
TabHost 3 (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);
}
}
<?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);
}
}
Minggu, 24 September 2017
TabHost 2 (memanggil screen)
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" >
</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);
}
}
<?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" >
</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);
}
}
Kamis, 17 Agustus 2017
Langganan:
Postingan (Atom)