Senin, 16 Oktober 2017

QUERY VB

Public Koneksi As New ADODB.Connection

Public Sub KoneksiDatabase()
On Error GoTo konekErr

If Koneksi.State = 1 Then Koneksi.Close
Koneksi.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\DBNILAI.mdb;Persist Security Info=False"
Exit Sub

konekErr:
    MsgBox "Gagal menghubungkan ke Database ! Kesalahan pada : " & Err.Description, vbCritical, "Peringatan"
End Sub


Private Sub Form_Load()
Dim kodecari As String
kodecari = "M1"
KoneksiDatabase
Adodc1.ConnectionString = Koneksi.ConnectionString
Adodc1.RecordSource = "SELECT * FROM MHS WHERE KodeMHS = '" & kodecari & "' "
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub


Silakan download

Sabtu, 14 Oktober 2017

Belajar Adapter (Daftar Kata) di Kamus

Layout daftarkata.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text = "Inggris"
android:textSize="20sp" />
<TextView
android:id="@+id/textView2"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView1"
android:text = "Indonesia"
android:textSize="20sp" />
<TextView
android:id="@+id/textView3"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView2"
android:text = "Jerman"
android:textSize="20sp" />
<ListView 
    android:id="@+id/list1" 
    android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:layout_weight = "1"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"/>
</RelativeLayout>

Layout untuk setiap item di ListView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:paddingBottom="5sp"
android:paddingTop="5sp" >
<TextView
android:id="@+id/inggris"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/indonesia"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/inggris" />
<TextView
android:id="@+id/jerman"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/indonesia" />
</RelativeLayout>

Class Controller untuk DaftaKata.java
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class DaftarKata extends Activity {
private DatabaseHelper dbhelper;
private SQLiteDatabase db = null;
private ListView listContent = null;
private Cursor kamusCursor = null;
CustomCursorAdapter adapter;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbhelper = new DatabaseHelper(this);
setContentView(R.layout.daftarkata);
listContent = (ListView) findViewById(R.id.list1);
isDataListView();
}
private void isDataListView() {
try {
db = dbhelper.getWritableDatabase();
kamusCursor = db.query("kamus", new String[] { "_id", "inggris",
"indonesia", "jerman" }, "_id>0", null, null, null, null);

/*
* Create an array to specify the fields we want to display in the
* list (only the 'inggris,indonesia,jerman' column in this case)
*/
String[] from = new String[] { "inggris", "indonesia", "jerman" };

/*
* and an array of the fields we want to bind those fieiplds to (in
* this case just the textView 'inggris,indonesia,jerman' from our new row.xml
* layout above)
*/
int[] to = new int[] { R.id.inggris, R.id.indonesia, R.id.jerman };

/* Now create a simple cursor adapter.. */
adapter = new CustomCursorAdapter(this, R.layout.row, kamusCursor,from, to);
listContent.setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (db != null && db.isOpen()) {
db.close();
}
}
}

@Override
public void onDestroy() {
super.onDestroy();
try {
kamusCursor.close();
} catch (Exception e) {
}
}

protected class CustomCursorAdapter extends SimpleCursorAdapter {
private int layout;
private LayoutInflater inflater;
private Context context;
public CustomCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super (context, layout, c, from, to);
this.layout = layout;
this.context = context;
inflater = LayoutInflater.from(context);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Log.d("NewView", "*****xxx");
View v = inflater.inflate(R.layout.row, parent, false);
return v;
}

@Override
public void bindView(View v, Context context, Cursor c) {
// 1 is the column where you're getting your data from
String inggris = c.getString(1);
String jerman = c.getString(3);
String indonesia = c.getString(2);

/**
* Next set the name of the entry.
*/
TextView name_text = (TextView) v.findViewById(R.id.inggris);
TextView des_text = (TextView) v.findViewById(R.id.jerman);
TextView id_text = (TextView) v.findViewById(R.id.indonesia);
des_text.setText(jerman);
id_text.setText(indonesia);

if (name_text != null) {
name_text.setText(inggris);
}
}
}
}

Senin, 09 Oktober 2017

Android SQLite

Class Kamus
public class Kamus {
private String istilah;
private String arti;
private String baru;

public String getIstilah() {
return istilah;
}

public void setIstilah(String istilah) {
this.istilah = istilah;
}

public String getArti() {
return arti;
}

public void setArti(String arti) {
this.arti = arti;
}

public String getBaru() {
return baru;
}

public void setBaru(String baru) {
this.baru = baru;
}

@Override
public String toString() {
return this.istilah;
}
}

Class DatabaseHelper
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

public class DatabaseHelper extends SQLiteAssetHelper {
private static final String DB_NAME = "db_kamus10";
private static final int DB_VER = 1;

private static final String TB_DATA = "tb_kamus";
public static final String COL_ID = "_id";
public static final String COL_ISTILAH = "istilah";
public static final String COL_ARTI = "arti";
public static final String COL_BARU = "baru";

private static DatabaseHelper dbInstance;
private static SQLiteDatabase db;

private DatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VER);
}

public static DatabaseHelper getInstance(Context context) {
if (dbInstance == null) {
dbInstance = new DatabaseHelper(context);
db = dbInstance.getWritableDatabase();
}
return dbInstance;
}

@Override
public synchronized void close() {
super.close();
if (dbInstance != null) {
dbInstance.close();
}
}

public List<Kamus> getAllKamus() {
List<Kamus> lisKamus = new ArrayList<Kamus>();

Cursor cursor = db.query(TB_DATA, new String[] { COL_ID, COL_ID,
COL_ARTI, COL_BARU,  COL_ISTILAH}, null, null, null, null, COL_ISTILAH);
if (cursor.getCount() >= 1) {
cursor.moveToFirst();

do {
Kamus kamus = new Kamus();
kamus.setArti(cursor.getString(cursor.getColumnIndexOrThrow(COL_ARTI)));
kamus.setBaru(cursor.getString(cursor.getColumnIndexOrThrow(COL_BARU)));
kamus.setIstilah(cursor.getString(cursor.getColumnIndexOrThrow(COL_ISTILAH)));
lisKamus.add(kamus);

} while (cursor.moveToNext());
}
return lisKamus;

}
}

Class MainActivity
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class MainActivity extends Activity implements TextWatcher, OnItemClickListener {
private EditText search;
private ListView lv;
private DatabaseHelper dbHelper;
private ArrayAdapter<Kamus> adapter;
private List<Kamus> listKamus;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.lv_data);
lv.setEmptyView(findViewById(R.id.empty));
search = (EditText) findViewById(R.id.search);
dbHelper = DatabaseHelper.getInstance(this);
setData();
search.addTextChangedListener(this);
lv.setOnItemClickListener(this);

}

private void setData() {
listKamus = dbHelper.getAllKamus();

adapter = new ArrayAdapter<Kamus>(this,
android.R.layout.simple_expandable_list_item_1, listKamus);
lv.setAdapter(adapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long id) {
// TODO Auto-generated method stub
Bundle b = new Bundle();
b.putString("istilah", adapter.getItem(position).getIstilah());
b.putString("arti", adapter.getItem(position).getArti());
b.putString("baru", adapter.getItem(position).getBaru());
Intent i = new Intent(this, ArtiActivity.class);
i.putExtras(b);
startActivity(i);
finish();
}

@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub

}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub

}

@Override
public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
adapter.getFilter().filter(s.toString());
}
}

Class ArtiActivity
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class ArtiActivity extends Activity {
private TextView txtBaru, txtArti, txtIstilah;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_arti);
Bundle b = getIntent().getExtras();
txtIstilah = (TextView) findViewById(R.id.istilah);
txtArti = (TextView) findViewById(R.id.arti);
txtBaru = (TextView) findViewById(R.id.baru);
txtIstilah.setText(b.getString("istilah"));
txtArti.setText(b.getString("arti"));
txtBaru.setText(b.getString("baru"));
}
}

Layout activity_arti
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ArtiActivity" >
    <TextView
        android:id="@+id/istilah"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Istilah" />
    <TextView
        android:id="@+id/garis"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@id/istilah"
        android:background="#000" />    
    <TextView
        android:id="@+id/baru"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/garis"
        android:text="Baru" />
    <TextView
        android:id="@+id/arti"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/baru"
        android:text="Arti" />
</RelativeLayout>

Database VB1









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(); 
    } 
    

}

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);
        }
    }
}

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);

}
}

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);

}
}