Membuat Aplikasi Android Data_Karyawan dengan Eclipse
Assalammualaikum Wr. Wb.
Manipulasi Class Untuk Mempercantik Background.
Sebelumnya kita hanya merubah sebuah warna background program dari hitam menjadi biru, sekarang kita akan membahas bagaiman membuat sebuah bakcground namun memiliki ujung yang tumpul, yang nantinya background ini akan kita pakai pada layout kedua dari program yg tadi.
langsung saja klik folder res, buat sebuah folder baru dengan cara klik kanan folder res-new-folder. Beri nama folder baru tersebut dengan nama drawable. Maka kita akan mempunya sebuah folder baru dengan nama drawable seperti gambar dibawah ini :
Hai, saya Abdul Gopur..
disini saya akan membahas belajar membuat Aplikasi Android misalnya Aplikasi Data_Karyawan sebuah perusahaan, seperti : Biodata Karyawan, perhitungan Gaji.
namun, aplikasi disini belum pake Database yah, hanya menampilkan output biodata dan perhitungan gaji. insyaAllah nanti akan saya kembangkan menggunakan Database, dan menu-menu lainnya.
Disini saya akan membuat kurang lebih 5 buah Activity.
-halaman depan
-halaman Login
-halaman Menu
-Input biodata
-perhitungan gaji
Disini saya akan membuat kurang lebih 5 buah Activity.
-halaman depan
-halaman Login
-halaman Menu
-Input biodata
-perhitungan gaji
Baik, langsung saja buka Eclipse nya, kemudian buat New Android Project / ctrl+n. atau
klik link: Membuat aplikasi android
klik link: Membuat aplikasi android
Pada bagian Project Name isikan dengan Data Karyawan.APK, build target pilih
android 2.2. Selanjutnya pada bagian properties isikan seperti data dibawah ini :
1. Application Name : Data Karyawan.APK
Package Name : com.datakaryawan
Create Activity : myMain
Min SDK Version : 8
Kemudian Edit file main.xml tersebut menjadi seperti coding xml dibawah ini :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000ff">
<LinearLayout
android:orientation="vertical"
android:background = "@drawable/manipulasi_background"
android:layout_marginLeft = "5dp"
android:layout_marginRight= "5dp"
android:layout_marginTop = "5dp"
android:layout_marginBottom = "5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:src="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dibuat Oleh :"
android:gravity="center"
android:textColor="#0000ff" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Abdul Gopur"
android:textColor="#ffff00"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="161011401372"
android:textColor="#ffff00"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="06TPLM001"
android:textColor="#ffff00"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center" />
<Button
android:id="@+id/next"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffa500"
android:textColor="#ffffff"
android:text="Next >>>"/>
</LinearLayout>
</LinearLayout>
cek digraphical layoutnya, tampilannya kurang lebih seperti ini:
Sebelum kita lanjut, ada baiknya kita mengulang/membahas sedikit tentang Toolbox dan Layout.
Android Widget Toolbox
Android memiliki standard toolbox Views untuk membantu anda merancang sebuah tampilan sederhana.
Beberapa toolbox yang sering digunakan dalam merancang sebuah tampilan program di Android seperti berikut ini.
- TextView = TextView merupakan teks yang hanya bisa dibaca (read only) atau jika kita terbiasa membuat sebuah aplikasi desktop menggunakan Java atau VB, TextView dapat disamakan dengan Label.
- EditText = Digunakan untuk memasukan data, sehingga user dapat menuliskan suatu nilai kedalam EditText tersebut.
- ListView = Digunakan untuk menampilkan item didalam list.
- Spinner = Widget yang menampilkan TextView dan berhubungan dengan ListView, sehingga memungkinkan user untuk memilih salah satu menu yang terdapat didalam Spinner tersebut.
- Button = Tombol yang biasanya digunakan untuk eksekusi perintah.
- CheckBox = Tombol yang merepresentasikan apakah terpilih (checked) atau tidak (unchecked).
- RadioButton = Tombol-tombol yang ditampilkan secara group, biasanya digunakan untuk user memilih salah satu dari tombol yang ada pada RadioButton tersebut.
- dan masih banyak toolbox lainnya sesuai fungsinya masing-masing.
Nanti kita akan mencoba membuat masing-masing dari widget tersebut, namun sebenarnya
itu hanya beberapa widget yang dimiliki oleh Android. Untuk daftar lengkapnya mengenai widget,
Anda bisa mencarinya di google yah hehe..
Layouts
Layout Managers (Biasa disebut dengan Layouts) digunakan untuk mengontrol posisi utama
dari layar. Layouts dapat di lekatkan (embed) dengan layout lainnya, jadi dengan kata lain Anda
dapat memasukan lebih dari satu buah layout pada tampilan yang nantinya akan dibuat.
Android SDK juga menyediakan beberapa layouts sederhana untuk membantu anda membangun tampilan program. Jadi Anda tinggal memilih ingin menggunakan layout yang mana saja untuk membuat tampilan program yang nantinya akan dibuat menjadi mudah dimengerti dan digunakan.
Beberapa layouts yang terdapat pada Android :
itu hanya beberapa widget yang dimiliki oleh Android. Untuk daftar lengkapnya mengenai widget,
Anda bisa mencarinya di google yah hehe..
Layout Managers (Biasa disebut dengan Layouts) digunakan untuk mengontrol posisi utama
dari layar. Layouts dapat di lekatkan (embed) dengan layout lainnya, jadi dengan kata lain Anda
dapat memasukan lebih dari satu buah layout pada tampilan yang nantinya akan dibuat.
Android SDK juga menyediakan beberapa layouts sederhana untuk membantu anda membangun tampilan program. Jadi Anda tinggal memilih ingin menggunakan layout yang mana saja untuk membuat tampilan program yang nantinya akan dibuat menjadi mudah dimengerti dan digunakan.
Beberapa layouts yang terdapat pada Android :
- FrameLayout = Layouts yang paling sederhana, FrameLayout menampilkan setiap view di kiri atas.
- LinearLayout = LinearLayout menambahkan setiap child View secara datar, artinya
- LinearLayout hanya menampilkan satu buah child View perbaris.
- RelativeLayout = Dengan menggunakan RelativeLayout, Anda mendefinisikan posisi dari masing-masing child View menjadi relatif.
- TableLayout = TableLayout memungkinkan layout ditampilkan secara garis dan kolom atau mirip tabel (ya namanya juga tablelayout).
- AbsoluteLayout = Setiap child View di definisikan dalam kordinat.
baik, next sebelum ke membuat Activity baru, saya akan membahas sedikit untuk mempercantik background dan menambah logo/gambar , agar kita tidak bosan dengan background warna hitam/putih .
Untuk mempermudah dan mempercepat pembahasan, buka kembali program awal/Data Karyawan yang sebelumnya sudah dibuat, lalu buka file main.xml nya lalu lakukan penambahan properties pada bagian Layout pertama, seperti dibawah ini :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000ff">
maka warna background nya akan berubah sesuai kode warna yaitu, #0000FF. atau warnanya sesuaikan dengan selera masing", cari aja kode warnanya di mbah google yah,, hehe..
Manipulasi Class Untuk Mempercantik Background.
Sebelumnya kita hanya merubah sebuah warna background program dari hitam menjadi biru, sekarang kita akan membahas bagaiman membuat sebuah bakcground namun memiliki ujung yang tumpul, yang nantinya background ini akan kita pakai pada layout kedua dari program yg tadi.
langsung saja klik folder res, buat sebuah folder baru dengan cara klik kanan folder res-new-folder. Beri nama folder baru tersebut dengan nama drawable. Maka kita akan mempunya sebuah folder baru dengan nama drawable seperti gambar dibawah ini :
nah, folder drawable ini juga bisa untuk menyimpan gambar yang kita copy dari window explorer.
caranya cukup simple yaitu, klik gambar yg ada di win.explorer, lalu drag/tarik ke folder drawable.
selanjutnya adalah membuat sebuah file xml baru yang nantinya digunakan untuk mempercantik tampilan background program. klik kanan folder drawable tersebut lalu pilih new-other, lalu akan terbuka sebuah jendela baru, pilih folder Android-Android XML File lalu klik next. Pada file, isikan dengan nama manipulasi_background (tidak boleh ada spasi), lalu pada klik layout pada type resourcenya lalu klik finish.
Biasanya file xml yang baru dibuat tersebut tidak langsung berada di dalam folder drawable, biasanya file tersebut ada didalam folder layout, jadi Anda tinggal pindahkan saja file xml tersebut ke dalam folder drawable dengan cara klik kanan file manipulasi_background.xml pilih copy, lalu paste kedalam folder drawable, file manipulasi_background yang ada didalam folder layout Anda hapus saja, maka sekarang file manipulasi_background tersebut sudah ada didalam folder drawable.
Sekarang buka file manipulasi_background tersebut lalu isikan dengan coding seperti dibawah ini :
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid
android:color="#20b2aa"
/>
<stroke
android:width="2dip"
android:color="#ffa500"
/>
<corners
android:radius="10dip"
/>
<padding
android:left="15dip"
android:right="10dip"
android:top="10dip"
android:bottom="10dip"
/>
</shape>
</item>
</selector>
Setelah selesai, selanjutnya buka file main.xml program yang pertama dan tambahkan <LinearLayout/> seperti dibawah ini :
<LinearLayout
android:orientation="vertical"
android:background = "@drawable/manipulasi_background"
android:layout_marginLeft = "5dp"
android:layout_marginRight= "5dp"
android:layout_marginTop = "5dp"
android:layout_marginBottom = "5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
untuk lengkapnya seperti ini main.xml nya:
caranya cukup simple yaitu, klik gambar yg ada di win.explorer, lalu drag/tarik ke folder drawable.
selanjutnya adalah membuat sebuah file xml baru yang nantinya digunakan untuk mempercantik tampilan background program. klik kanan folder drawable tersebut lalu pilih new-other, lalu akan terbuka sebuah jendela baru, pilih folder Android-Android XML File lalu klik next. Pada file, isikan dengan nama manipulasi_background (tidak boleh ada spasi), lalu pada klik layout pada type resourcenya lalu klik finish.
Biasanya file xml yang baru dibuat tersebut tidak langsung berada di dalam folder drawable, biasanya file tersebut ada didalam folder layout, jadi Anda tinggal pindahkan saja file xml tersebut ke dalam folder drawable dengan cara klik kanan file manipulasi_background.xml pilih copy, lalu paste kedalam folder drawable, file manipulasi_background yang ada didalam folder layout Anda hapus saja, maka sekarang file manipulasi_background tersebut sudah ada didalam folder drawable.
Sekarang buka file manipulasi_background tersebut lalu isikan dengan coding seperti dibawah ini :
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid
android:color="#20b2aa"
/>
<stroke
android:width="2dip"
android:color="#ffa500"
/>
<corners
android:radius="10dip"
/>
<padding
android:left="15dip"
android:right="10dip"
android:top="10dip"
android:bottom="10dip"
/>
</shape>
</item>
</selector>
Setelah selesai, selanjutnya buka file main.xml program yang pertama dan tambahkan <LinearLayout/> seperti dibawah ini :
<LinearLayout
android:orientation="vertical"
android:background = "@drawable/manipulasi_background"
android:layout_marginLeft = "5dp"
android:layout_marginRight= "5dp"
android:layout_marginTop = "5dp"
android:layout_marginBottom = "5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
untuk lengkapnya seperti ini main.xml nya:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000ff">
<LinearLayout
android:orientation="vertical"
android:background = "@drawable/manipulasi_background"
android:layout_marginLeft = "5dp"
android:layout_marginRight= "5dp"
android:layout_marginTop = "5dp"
android:layout_marginBottom = "5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:src="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dibuat Oleh :"
android:gravity="center"
android:textColor="#0000ff" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Abdul Gopur"
android:textColor="#ffff00"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="161011401372"
android:textColor="#ffff00"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="06TPLM001"
android:textColor="#ffff00"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center" />
<Button
android:id="@+id/next"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffa500"
android:textColor="#ffffff"
android:text="Next >>>"/>
</LinearLayout>
</LinearLayout>
Kemudian buka MainActivity.java. dan masukan codingan agar bisa di eksekusi atau masuk ke halaman Login.
caranya klik src_MainActivity.java. atau seperti gambar berikut.
lalu masukan codingan seperti berikut ini:
package com.datakaryawan;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button next;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
next = (Button) findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
openLoginActivity(arg0);
}
});
}
public void openLoginActivity(View v){
Intent i = new Intent(this, LoginActivity.class);
startActivityForResult(i, 0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
setelah di run akan seperti ini:
klik tombol Next, maka secara otomatis akan masuk ke Halaman Login.
Catatan: sebelumnya buat dulu Activity baru, seperti ActivityLogin.
Kemudian buka MainActivity.java. dan masukan codingan agar bisa di eksekusi atau masuk ke halaman Login.
caranya klik src_MainActivity.java. atau seperti gambar berikut.
lalu masukan codingan seperti berikut ini:
package com.datakaryawan;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button next;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
next = (Button) findViewById(R.id.next);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
openLoginActivity(arg0);
}
});
}
public void openLoginActivity(View v){
Intent i = new Intent(this, LoginActivity.class);
startActivityForResult(i, 0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
setelah di run akan seperti ini:
klik tombol Next, maka secara otomatis akan masuk ke Halaman Login.
Catatan: sebelumnya buat dulu Activity baru, seperti ActivityLogin.
atau
klik :Menambah Activity baru
<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"
tools:context=".MenuActivity" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
3.2 Graphical_Layout
3.3 MenuActivity.java
package com.datakaryawan;
import android.os.Bundle;
import android.app.ListActivity;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
public class MenuActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
TabHost tabhost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, HomeActivity.class);
spec = tabhost.newTabSpec("Home").setIndicator("Home",null).setContent(intent);
tabhost.addTab(spec);
intent = new Intent().setClass(this, BiodataActivity.class);
spec = tabhost.newTabSpec("Biodata").setIndicator("Biodata",null).setContent(intent);
tabhost.addTab(spec);
intent = new Intent().setClass(this, PerhitunganGajiActivity.class);
spec = tabhost.newTabSpec("Gaji").setIndicator("Gaji",null).setContent(intent);
tabhost.addTab(spec);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_menu, menu);
return true;
}
}
Setelah di run
4. MENU HOME
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000ff">
<LinearLayout
android:orientation="vertical"
android:background = "#ffa07a"
android:layout_marginLeft = "5dp"
android:layout_marginRight= "5dp"
android:layout_marginTop = "5dp"
android:layout_marginBottom = "5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:src="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Abdul Gopur"
android:textColor="#0000ff"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="161011401372"
android:textColor="#0000ff"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="06TPLM001"
android:textColor="#0000ff"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center" />
</LinearLayout>
</LinearLayout>
4.2 Graphical_Layout
5. MENU BIODATA
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="424dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#e0ffff"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama" />
<EditText
android:id="@+id/nama"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Usia" />
<EditText
android:id="@+id/usia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alamat" />
<EditText
android:id="@+id/alamat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<Button
android:id="@+id/ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Input" />
<TextView
android:id="@+id/output"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="" />
<TextView
android:id="@+id/outputalamat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
<TextView
android:id="@+id/outputusia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
2. Halaman Login
2.1. activity_login.xml
<?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:background="#dcdcdc"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="HALAMAN LOGIN"
android:textColor="#0000cd" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="" />
<EditText
android:id="@+id/user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Username"
android:textColor="#808080" />
<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center"
android:inputType="textPassword"
android:text="password"
android:textColor="#808080" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="67dp"
android:gravity="center" >
<Button
android:id="@+id/login"
android:layout_width="113dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#87ceeb"
android:text="LOGIN"
android:textColor="#0000ff" />
</RelativeLayout>
</LinearLayout>
2.2. Graphical_Layout
2.3. LoginActivity.java
package com.datakaryawan;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity {
EditText user, password;
Button Login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
user = (EditText) findViewById(R.id.user);
password = (EditText) findViewById(R.id.password);
Login = (Button) findViewById(R.id.login);
Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
login(arg0);
}
});
}
public void login(View view) {
String Nama = user.getText().toString();
String Pass = password.getText().toString();
if (Nama.equals("admin") && Pass.equals("1")) {
Intent i = new Intent(this, MenuActivity.class);
startActivityForResult(i, 0);
}
else {
Toast.makeText(getApplicationContext(),
"Password atau username salah, silahkan diulang",
Toast.LENGTH_LONG).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_login, menu);
return true;
}
}
setelah di run :
3. HALAMAN MENU
3.1 activity_menu.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MenuActivity" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
3.2 Graphical_Layout
3.3 MenuActivity.java
package com.datakaryawan;
import android.os.Bundle;
import android.app.ListActivity;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
public class MenuActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
TabHost tabhost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, HomeActivity.class);
spec = tabhost.newTabSpec("Home").setIndicator("Home",null).setContent(intent);
tabhost.addTab(spec);
intent = new Intent().setClass(this, BiodataActivity.class);
spec = tabhost.newTabSpec("Biodata").setIndicator("Biodata",null).setContent(intent);
tabhost.addTab(spec);
intent = new Intent().setClass(this, PerhitunganGajiActivity.class);
spec = tabhost.newTabSpec("Gaji").setIndicator("Gaji",null).setContent(intent);
tabhost.addTab(spec);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_menu, menu);
return true;
}
}
Setelah di run
4. MENU HOME
4.1 activity_home.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000ff">
<LinearLayout
android:orientation="vertical"
android:background = "#ffa07a"
android:layout_marginLeft = "5dp"
android:layout_marginRight= "5dp"
android:layout_marginTop = "5dp"
android:layout_marginBottom = "5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:src="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Abdul Gopur"
android:textColor="#0000ff"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="161011401372"
android:textColor="#0000ff"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="06TPLM001"
android:textColor="#0000ff"
android:gravity="center" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center" />
</LinearLayout>
</LinearLayout>
4.2 Graphical_Layout
5. MENU BIODATA
5.1 activity_biodata.xml
<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"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="424dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#e0ffff"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama" />
<EditText
android:id="@+id/nama"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Usia" />
<EditText
android:id="@+id/usia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alamat" />
<EditText
android:id="@+id/alamat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<Button
android:id="@+id/ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Input" />
<TextView
android:id="@+id/output"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="" />
<TextView
android:id="@+id/outputalamat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
<TextView
android:id="@+id/outputusia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
5.2 Graphical_Layout
5.3 BiodataActivity.java
package com.datakaryawan;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class BiodataActivity extends Activity {
EditText Nama, usia,alamat;
Button Ok;
TextView output, outputusia, outputalamat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_biodata);
Ok = (Button) findViewById(R.id.ok);
output = (TextView)findViewById(R.id.output);
outputusia= (TextView) findViewById(R.id.outputusia);
outputalamat= (TextView) findViewById(R.id.outputalamat);
Ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
input(arg0);
}
});
}
public void input (View v){
Nama= (EditText) findViewById(R.id.nama);
Nama.getText().toString();
String Name = String.valueOf(Nama.getText().toString());
output.setText("Nama Anda Adalah " +Name);
usia= (EditText) findViewById(R.id.usia);
usia.getText().toString();
String Name1 = String.valueOf(usia.getText().toString());
outputusia.setText("Usia Anda Adalah " +Name1);
alamat= (EditText) findViewById(R.id.alamat);
alamat.getText().toString();
String Name2 = String.valueOf(alamat.getText().toString());
outputalamat.setText("Anda Tinggal di " +Name2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_biodata, menu);
return true;
}
}
6. MENU PENGHITUNGAN GAJI
6.1 activity_perhitungan_gaji.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#070898"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_width = "fill_parent"
android:layout_height= "wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="424dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/manipulasi_background"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Masukan Nama Anda :"
android:textColor="#000000" />
<EditText
android:id="@+id/nama"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Status"
android:textColor="#000000" />
<CheckBox
android:id="@+id/menikah"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menikah"
android:textColor="#000000" />
<CheckBox
android:id="@+id/lajang"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="lajang"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Golongan"
android:textColor="#000000" />
<RadioGroup
android:id="@+id/rgGolongan"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rbGolongan1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Golongan 1"
android:textColor="#000000" />
<RadioButton
android:id="@+id/rbGolongan2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Golongan 2"
android:textColor="#000000" />
</RadioGroup>
<Button
android:layout_width="fill_parent"
android:layout_height="49dp"
android:layout_marginTop="15dp"
android:layout_weight="0.36"
android:onClick="hitung"
android:text="Hitung" />
<TextView
android:id="@+id/outputNama"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:textColor="#000000"
android:textSize="20dp" />
<TextView
android:id="@+id/outputStatus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:textColor="#000000"
android:textSize="20dp" />
<TextView
android:id="@+id/outputGaji"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:textColor="#000000"
android:textSize="35dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
6.3 PerhitunganGajiActivity.java
package com.datakaryawan;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class PerhitunganGajiActivity extends Activity {
int gajistatus, gajigolongan;
RadioButton gol1, gol2;
RadioGroup golongan;
Button hitung;
CheckBox status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_perhitungan_gaji);
}
public void hitung(View v){
EditText nama=(EditText) findViewById(R.id.nama);
TextView outputnama= (TextView) findViewById(R.id.outputNama);
String name = nama.getText().toString();
outputnama.setText("Total Gaji " +name);
status=(CheckBox) findViewById(R.id.menikah);
if (status.isChecked()){
gajistatus = 50000;
};
golongan=(RadioGroup) findViewById(R.id.rgGolongan);
int gol = golongan.getCheckedRadioButtonId();
if (gol == R.id.rbGolongan1){
gajigolongan=1000000;
}else
if (gol== R.id.rbGolongan2){
gajigolongan=2000000;
};
int TotalGaji= gajistatus + gajigolongan;
TextView total= (TextView) findViewById(R.id.outputGaji);
total.setText(String.valueOf(TotalGaji));
}
};
Setelah di run.
baik, sampai disini dulu yah belajarnya, mudah"an bermanfaat dan mohon maaf dalam belajar android ini masih banyak kekurangan dan kesalahan. insyaAllah pada suatu kesempatan saya akan upload belajar android lainnya.
terima kasih.
terima kasih.
Komentar
Posting Komentar