Assalamualaikum Wr.Wb
Disini
saya ingin membuat membuat aplikasi forum Agen Penjualan Tiket kereta Api
berbasis Android menggunakan ADT(Android Developer Tools) Eclipse.
1. Buka
aplikasi Eclipsenya
2. Pilih tempat untuk menjadi penyimpanan
projectnya
3. Lalu
buat projectnya dengan klik File =>
New => Android Application Project => beri nama project, tentukan minimum
dan target SDKnya =>next =>next=>finish.
4. Lalu
buat Android activity Sebanyak gambar dibawah :
5. Buat
design layoutnya
1). Activity_login.xml
Code xml login :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:orientation="vertical"
>
<TextView
android:id="@+id/data_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="SELAMAT DATANG DI FORUM"
android:textSize="20dp" />
<TextView
android:id="@+id/data1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="AGEN
PENJUALAN TIKET KERETA API"
android:textSize="15dp" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView
android:id="@+id/data_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Login "
android:textSize="25dp" />
<EditText
android:id="@+id/txtusername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Username"
android:singleLine="true"
>
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtpassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:password="true"
/>
<Button
android:id="@+id/btnSimpan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Masuk"
/>
</LinearLayout>
2). Activity_list.xml
Code xmlnya :
<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="com.example.aplikasitiket.ListActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
3).Bikin design untuk masing-masing Activity xml
untuk kota yang lainnya seperti
Activity_cirebon.xml
Code xmlnya :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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="com.example.projectuts.MainActivity" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="436dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Nama :" />
<EditText
android:id="@+id/ednama"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alamat :" />
<EditText
android:id="@+id/edalamat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kelas
:" />
<RadioGroup
android:id="@+id/rgkelas"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rbekonomi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Ekonomi"
/>
<RadioButton
android:id="@+id/rbvip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vip"
/>
</RadioGroup>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Service
:" />
<CheckBox
android:id="@+id/chmakan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Makanan" />
<CheckBox
android:id="@+id/chminum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Minuman" />
<Button
android:id="@+id/button1"
android:onClick="hitungbiaya"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hitung" />
<TextView
android:id="@+id/tvharga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hasil" />
</LinearLayout>
</ScrollView>
</LinearLayout>
6. Jangan
lupa untuk mengganti nama id pada setiap TextView,Button,RadioButton,RadioGroup,Chekbok
dan ListView nya.
7. Masukan
source code dibawah ini pada
1). LoginActivity.java
package com.example.aplikasitiket;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity
{
String pasw ;
String nama;
String namaku ="admin";
String pswd ="admin";
EditText name;
EditText pass,tampil;
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
name
= (EditText)findViewById(R.id.txtusername);
pass =
(EditText)findViewById(R.id.txtpassword);
Button submit =
(Button)findViewById(R.id.btnSimpan);
submit.setOnClickListener(new
click());
}
@SuppressLint("ShowToast")
class click implements Button.OnClickListener{
@SuppressLint("ShowToast")
public void onClick(View v){
nama = name.getText().toString();
pasw = pass.getText().toString();
if((pasw.equals(pswd))&&(nama.equals(namaku))){
Toast.makeText(getApplicationContext(),"Selamat datang, anda
berhasil
login...",31).show();
Intent i = new Intent(LoginActivity.this,
ListActivity.class);
startActivity(i);
}else
Toast.makeText(getApplicationContext(),"Ma'af...,
Username atau password
salah",23).show();
name.setText("");
pass.setText("");
}
}
@Override
public
boolean onCreateOptionsMenu(Menu menu) {
//
Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login,
menu);
return
true;
}
@Override
public
boolean onOptionsItemSelected(MenuItem item) {
//
Handle action bar item clicks here. The action bar will
//
automatically handle clicks on the Home/Up button, so long
//
as you specify a parent activity in AndroidManifest.xml.
int
id = item.getItemId();
if (id == R.id.action_settings)
{
return
true;
}
return
super.onOptionsItemSelected(item);
}
}
2). ListActivity.java
package com.example.aplikasitiket;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListActivity extends Activity
{
ListView LV;
String [] Menu =
{"Cirebon","Solo","Madura","Yogyakarta","Bandung","Malang","Bondowoso","Surabaya"
,"Banyumas"};
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
LV
= (ListView)findViewById(R.id.listView1);
ArrayAdapter adapter = new
ArrayAdapter(this
,android.R.layout.simple_list_item_single_choice,Menu);
LV.setAdapter(adapter);
LV.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
String
Itemtext=(String) LV.getItemAtPosition(position);
if(Itemtext.equals("Cirebon")){
Intent
Cirebon = new Intent(parent.getContext(),CirebonActivity.class);
startActivityForResult(Cirebon,0);;
}else
if(Itemtext.equals("Solo")){
Intent
Solo = new Intent(parent.getContext(),SoloActivity.class);
startActivityForResult(Solo,0);;
}else
if(Itemtext.equals("Madura")){
Intent
Madura = new Intent(parent.getContext(),MaduraActivity.class);
startActivityForResult(Madura,0);;
}else
if(Itemtext.equals("Yogyakarta")){
Intent
yogya = new Intent(parent.getContext(),YogyakartaActivity.class);
startActivityForResult(yogya,0);;
}else
if(Itemtext.equals("Bandung")){
Intent
bandung = new Intent(parent.getContext(),BandungActivity.class);
startActivityForResult(bandung,0);;
}else
if(Itemtext.equals("Malang")){
Intent
malang = new Intent(parent.getContext(),MalangActivity.class);
startActivityForResult(malang,0);;
}else
if(Itemtext.equals("Bondowoso")){
Intent
bondo = new Intent(parent.getContext(),BondowosoActivity.class);
startActivityForResult(bondo,0);;
}else
if(Itemtext.equals("Surabaya")){
Intent
Surabaya = new Intent(parent.getContext(),SurabayaActivity.class);
startActivityForResult(Surabaya,0);;
}else
if(Itemtext.equals("Banyumas")){
Intent
Banyu = new Intent(parent.getContext(),BanyumasActivity.class);
startActivityForResult(Banyu,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.list,
menu);
return
true;
}
@Override
public
boolean onOptionsItemSelected(MenuItem item) {
//
Handle action bar item clicks here. The action bar will
//
automatically handle clicks on the Home/Up button, so long
//
as you specify a parent activity in AndroidManifest.xml.
int
id = item.getItemId();
if
(id == R.id.action_settings) {
return
true;
}
return
super.onOptionsItemSelected(item);
}
}
3). CirebonActivity.java
package com.example.aplikasitiket;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.CheckBox;
import java.text.NumberFormat;
import java.text.DecimalFormat;
public class CirebonActivity extends
Activity {
int
hargatiket,biayakelas,biayaservicemakan,biayaserviceminum;
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cirebon);
}
public
void hitungbiaya(View v) {
EditText
nama = (EditText)findViewById(R.id.ednama);
String
Nama = nama.getText().toString();
RadioGroup
kelas =(RadioGroup)findViewById(R.id.rgkelas);
int
kls = kelas.getCheckedRadioButtonId();
if
(kls == R.id.rbvip) {
biayakelas=1500000;
}else
if (kls == R.id.rbekonomi) {
biayakelas=500000;
}
CheckBox
servismeal = (CheckBox)findViewById(R.id.chmakan);
if
(servismeal.isChecked()) {
biayaservicemakan
= 75000;
}else
{
biayaservicemakan
= 0;
}
CheckBox
servisdrink = (CheckBox)findViewById(R.id.chminum);
if
(servisdrink.isChecked()) {
biayaserviceminum
= 25000;
}else
{
biayaserviceminum
= 0;
}
Int totalbiaya =
hargatiket+biayakelas+biayaservicemakan+biayaserviceminum;
NumberFormat numberFormat = new DecimalFormat("#,###,###");
String str =
numberFormat.format(totalbiaya);
TextView totalharga =
(TextView)findViewById(R.id.tvharga);
totalharga.setText("Harga Tiket
Bpk/Ibu : "+Nama.toString() +"Rp."+ str);
}
@Override
public
boolean onCreateOptionsMenu(Menu menu) {
//
Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.cirebon,
menu);
return
true;
}
@Override
public
boolean onOptionsItemSelected(MenuItem item) {
//
Handle action bar item clicks here. The action bar will
//
automatically handle clicks on the Home/Up button, so long
//
as you specify a parent activity in AndroidManifest.xml.
int
id = item.getItemId();
if
(id == R.id.action_settings) {
return
true;
}
return
super.onOptionsItemSelected(item);
}
}
4).Masukkan source code yang di
CirebonActivity.java pada BandungActivity.java,
MalangActivity.java ,SurabayaActivity.java
,BanyumasActivity.java ,BondowosoActivity.java ,SoloActivity.java ,dan
YogyakartaAcitivity.java. dan ubah pas bagian harga tiketnya pada masing-masing
Activity yang diatas.
8. Setelah
dibuat design xmlnya dan codenya sudah dimasukkan lalu kita Run, disini saya
export dulu ke aplikasi.apk dikarenakan saya akan RUN nya digadget, caranya klik
kanan pada nama project yang tadi dibuat =>Export => Android => ExportAndroidApplication
lalu next => pilih tempat penyimpanan buat Exportnya lalu next => pilih
lokasi untuk menaruh key projectnya
=> bikin alias projectnya, dan tentukan validasi tahun projectnya =>
Finish.
9. Hasil
Run :
Sekian pembuatan project
Aplikasi Penjualan Tiketnya. Mohon maaf apabila kurang jelas penjelasannya.
Wassalamu'alaikum Wr.Wb