Assalamualaikum W.r W.b
Pada
kesempatan kali ini saya akan melanjutkan sebuah program aplikasi yang pernah
saya post sebelumnya yang berjudul “FORUM AGEN PENJUALAN TIKET KERETA API
BERBASIS ANDROID”, lalu di pembahasan kali ini saya akan menambahkan didalam
aplikasi nya beberapa atribut seperti imageviewer,tabhost,galeriimage,dan lainnya,
dan saya akan sedikit merubah aplikasi nya tetap bertemakan penjualan namun
saya membuat aplikasinya seperti sebuah Agen Travel, dan tanpa basa-basi mari
mulai saja.
Langah-langkahnya :
1. Buka
Aplikasi Eclipsenya
2. Setelah
dibuka, klik file =>New => Other
3. Pilih
Android
Application Project => Next
4. Isikan
nama aplikasinya, lalu tentukan minimum , dan target API nya => next
5. Sisanya
Tekan next saja, lalu finish
Setelah muncul seperti gambar
diatas.
6. Kita
buat file xml dan javanya
a. Xml
b. Java
7. Buatlah
folder drawable untuk menaruh gambar tout
destinasinya dan gambar untuk backgroundnya
8. Setelah
membuat file dan folder nya, design dan masukan codenya disetiap masing-masing
file java dan xml
nya
a. Design
Xml
1. Login.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background ="@drawable/a"
android:layout_gravity="center|center_vertical"
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.dealrajudwidermawan_161011400142.MainActivity_login"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="70dp"
android:text="Welcome to"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
/>
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:text="The Traveling
Indonesia"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="27dp"
android:layout_marginBottom="10dp"
android:textColor="#ffffff"
android:text="Login"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText
android:id="@+id/txtnama"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:ems="10"
android:textColorHint="#ffffff"
android:hint="Username"
android:inputType="text|textEmailAddress" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtpass"
android:layout_width="262dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:ems="10"
android:textColorHint="#ffffff"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/btnsimpan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ffffff"
android:text="Sign in" />
</LinearLayout>
2. Home.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:background="@drawable/a"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.dealrajudwidermawan_161011400142.HomeActivity"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:textColor="#ffffff"
android:text="Welcome To"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/textView2"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="The Traveling
Indonesia"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<Button
android:id="@+id/button1"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="58dp"
android:text="TOUR" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:textColor="#ffffff"
android:layout_marginTop="30dp"
android:text="TRANSAKSI"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
android:textColor="#ffffff"
android:text="GALERY" />
</RelativeLayout>
3. Tour.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.dealrajudwidermawan_161011400142.TourActivity"
>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
4. TourCirebon.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.dealrajudwidermawan_161011400142.TourBaliActivity"
>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/cirebon1" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Cirebon"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jika Anda
punya rencana liburan ke Cirebon, kota kecil ini menawarkan cukup banyak wisata
pilihan untuk Anda dikunjungi. Selama ini Kabupaten Cirebon terkenal dengan
wisata religi dan sejarah, namun ternyata kota ini juga memiliki tempat-tempat
wisata yang bernuansa alam yang tak kalah dengan wisata bandung ataupun kota
besar lainnya."
android:textAppearance="?android:attr/textAppearanceSmall"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Nb : untuk design xml TourBali,TourLampung,TourJogja,TourMalang,TourRaja,TourSolo,TourSurabaya,TourBandung,TourManado,TourMakassar, dan TourLombok saya buat sama dengan TourCirebon cuman beda gambar dan deksripsinya saja.
5. Galary.xml
Code xmlnya
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_followed_top"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:orientation="vertical"
>
<GridView
android:id="@+id/gridview_followed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
>
</GridView>
</LinearLayout>
Code xmlnya
<?xml
version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/singleimage"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:contentDescription="gambar
tunggal"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
/>
</LinearLayout>
7. Transportasi.xml
Code xmlnya
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
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.dealrajudwidermawan_161011400142.TransportasiActivity"
>
<TabHost
android1:id="@android:id/tabhost"
android1:layout_width="match_parent"
android1:layout_height="match_parent"
android1:layout_marginTop="18dp" >
<LinearLayout
android1:layout_width="match_parent"
android1:layout_height="match_parent"
android1:orientation="vertical" >
<TabWidget
android1:id="@android:id/tabs"
android1:layout_width="match_parent"
android1:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android1:id="@android:id/tabcontent"
android1:layout_width="match_parent"
android1:layout_height="match_parent" >
<LinearLayout
android1:id="@+id/tab1"
android1:layout_width="match_parent"
android1:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android1:id="@+id/tab2"
android1:layout_width="match_parent"
android1:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android1:id="@+id/tab3"
android1:layout_width="match_parent"
android1:layout_height="match_parent"
>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
8. Vip.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.dealrajudwidermawan_161011400142.VipActivity"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:textColor="#000000"
android:text="Kelas Vip"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_alignParentRight="true"
android:layout_below="@+id/button1"
android:textColor="#000000"
android:layout_marginTop="17dp"
android:text="Kapal Laut"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:textColor="#000000"
android:layout_alignParentRight="true"
android:layout_below="@+id/button2"
android:layout_marginTop="17dp"
android:text="Kereta" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignParentRight="true"
android:textColor="#000000"
android:layout_below="@+id/button3"
android:layout_marginTop="19dp"
android:text="Bus" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="38dp"
android:text="Pesawat" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button4"
android:textColor="#000000"
android:layout_below="@+id/button4"
android:layout_marginTop="40dp"
android:text="Kembali" />
</RelativeLayout>
Nb : untuk design Ekonomi.xml dan Bisnis.xml saya buat sama dengan Vip.xml
9. Bus.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.dealrajudwidermawan_161011400142.BusActivity"
>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
Nb : untuk design Pesawat.xml, Kapal.xml, dan Kereta.xml
Dibuat sama dengan Bus.xml
10. Cirebon.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.dealrajudwidermawan_161011400142.BaliActivity"
>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginBottom="10dp"
android:layout_marginTop="28dp"
android:text="Nama"
/>
<EditText
android:id="@+id/editText1"
android:layout_width="288dp"
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:layout_marginTop="10dp"
android:text="Email" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="No.Telp" />
<EditText
android:id="@+id/editText3"
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:layout_marginTop="10dp"
android:text="Harga :
Rp.500.000,00" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Jumlah" />
<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Total" />
<EditText
android:id="@+id/editText5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ems="10" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Nb : Design seperti didalam table sama seperti design Cirebon.xml
Bali.xml
|
Bali1.xml
|
Bali2.xml
|
Lampung.xml
|
Lampung1.xml
|
Lampung2.xml
|
Malang.xml
|
Malang1.xml
|
Malang2.xml
|
Bandung.xml
|
Bandung1.xml
|
Bandung2.xml
|
Surabaya.xml
|
Surabaya1.xml
|
Surabaya2.xml
|
Lombok.xml
|
Lombok1.xml
|
Lombok2.xml
|
Solo.xml
|
Solo1.xml
|
Solo2.xml
|
Manado.xml
|
Manado1.xml
|
Manado2.xml
|
Makassar.xml
|
Makassar1.xml
|
Makassar2.xml
|
Raja.xml
|
Raja1.xml
|
Raja2.xml
|
Jogja.xml
|
Jogja1.xml
|
Jogja2.xml
|
|
Cirebon1.xml
|
Cirebon2.xml
|
a. Source Code Java
1. MainActivity_Login.java
package
com.example.dealrajudwidermawan_161011400142;
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
MainActivity_login 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_main_activity_login);
name =
(EditText)findViewById(R.id.txtnama);
pass =
(EditText)findViewById(R.id.txtpass);
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(MainActivity_login.this, HomeActivity.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.main_activity_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);
}
}
package
com.example.dealrajudwidermawan_161011400142;
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
HomeActivity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Button Pesawat =
(Button)findViewById(R.id.button1);
Pesawat.setOnClickListener(new
View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method
stub
Intent i = new
Intent(HomeActivity.this, TourActivity.class);
i.putExtra("pesan",
"From Activity Main");
startActivity(i);
}
});
Button kapal =
(Button)findViewById(R.id.button2);
kapal.setOnClickListener(new
View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method
stub
Intent a = new Intent(HomeActivity.this,
GaleryActivity.class);
a.putExtra("pesan",
"From Activity Main");
startActivity(a);
}
});
Button kereta =
(Button)findViewById(R.id.button3);
kereta.setOnClickListener(new
View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method
stub
Intent j = new
Intent(HomeActivity.this, TransportasiActivity.class);
j.putExtra("pesan",
"From Activity Main");
startActivity(j);
}
});
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this
adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home,
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);
}
}
package
com.example.dealrajudwidermawan_161011400142;
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
TourActivity extends Activity {
ListView LV;
String [] Menu =
{"Cirebon","Jogja","Surabaya","Malang","Bandung","Manado","Solo","Makassar","Lampung","Bali","Lombok","Raja
Ampat"};
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tour);
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) {
// TODO
Auto-generated method stub
String
Itemtext=(String) LV.getItemAtPosition(position);
if(Itemtext.equals("Bali")){
Intent
Bali = new Intent(parent.getContext(),TourBaliActivity.class);
startActivityForResult(Bali,0);;
}else
if(Itemtext.equals("Lombok")){
Intent
Lombok = new Intent(parent.getContext(),TourLombokActivity.class);
startActivityForResult(Lombok,0);;
}else
if(Itemtext.equals("Raja Ampat")){
Intent
Raja = new Intent(parent.getContext(),TourRajaActivity.class);
startActivityForResult(Raja,0);;
}else
if(Itemtext.equals("Cirebon")){
Intent
cirebon = new Intent(parent.getContext(),TourCirebonActivity.class);
startActivityForResult(cirebon,0);;
}else
if(Itemtext.equals("Jogja")){
Intent
jogja = new Intent(parent.getContext(),TourJogjaActivity.class);
startActivityForResult(jogja,0);;
}else
if(Itemtext.equals("Surabaya")){
Intent
surabaya = new Intent(parent.getContext(),TourSurabayaActivity.class);
startActivityForResult(surabaya,0);;
}else
if(Itemtext.equals("Bandung")){
Intent
bandung = new Intent(parent.getContext(),TourBandungActivity.class);
startActivityForResult(bandung,0);;
}else
if(Itemtext.equals("Solo")){
Intent
solo = new Intent(parent.getContext(),TourSoloActivity.class);
startActivityForResult(solo,0);;
}else
if(Itemtext.equals("Manado")){
Intent
manado = new Intent(parent.getContext(),TourManadoActivity.class);
startActivityForResult(manado,0);;
}else
if(Itemtext.equals("Makassar")){
Intent
makassar = new Intent(parent.getContext(),TourMakassarActivity.class);
startActivityForResult(makassar,0);;
}else
if(Itemtext.equals("Lampung")){
Intent
lampung = new Intent(parent.getContext(),TourLampungActivity.class);
startActivityForResult(lampung,0);;
}else
if(Itemtext.equals("Malang")){
Intent
malang = new Intent(parent.getContext(),TourMalangActivity.class);
startActivityForResult(malang,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.tour,
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);
}
}
package
com.example.dealrajudwidermawan_161011400142;
import
android.os.Bundle;
import
android.app.Activity;
import
android.content.Intent;
import
android.view.View;
import android.view.View.OnClickListener;
import
android.widget.AdapterView;
import
android.widget.AdapterView.OnItemClickListener;
import
android.widget.GridView;
import
android.widget.Toast;
public class
GaleryActivity extends Activity implements OnItemClickListener,
OnClickListener{
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_galery);
GridView gridView =
(GridView) findViewById(R.id.gridview_followed);
gridView.setAdapter(new ImageAdapter
(this));
gridView.setOnItemClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method
stub
}
@Override
public void
onItemClick(AdapterView<?> parent, View v, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(GaleryActivity.this,
"Klik Gambar"+position, Toast.LENGTH_SHORT).show();
Intent i = new Intent(this,
SingleImage.class);
Bundle b = new Bundle();
b.putInt("posisi", position);
i.putExtras(b);
startActivity(i);
}
}
package
com.example.dealrajudwidermawan_161011400142;
import
android.content.Context;
import
android.view.View;
import
android.view.ViewGroup;
import
android.widget.BaseAdapter;
import
android.widget.GridView;
import
android.widget.ImageView;
class
ImageAdapter extends BaseAdapter{
private Context mContext;
public ImageAdapter(Context c)
{
mContext = c;
}
public static Integer[] mThumbIds =
{
//Gambar-gambar yang ada disimpan
dalam array
R.drawable.cirebon1,
R.drawable.cirebon,
R.drawable.bandung,
R.drawable.bandung1,
R.drawable.bandung2,
R.drawable.cirebon2,
R.drawable.bali1,
R.drawable.bali,
R.drawable.bali2,
R.drawable.lampung1,
R.drawable.lampung,
R.drawable.lampung2,
R.drawable.lombok1,
R.drawable.lombok,
R.drawable.lombok2,
R.drawable.kuta,
R.drawable.jogja,
R.drawable.jogja1,
R.drawable.jogja2,
R.drawable.malang,
R.drawable.makassar2,
R.drawable.makassar,
R.drawable.mnado2,
R.drawable.makassar1,
R.drawable.raja2,
R.drawable.raja,
R.drawable.solo2,
R.drawable.solo,
R.drawable.raja1,
R.drawable.solo1,
R.drawable.surabaya2,
R.drawable.surabaya,
R.drawable.surabaya1,
R.drawable.cirebon3,
R.drawable.manado1,
R.drawable.manado,
R.drawable.malang,
R.drawable.malang2
};
@Override
public int getCount() {
// TODO Auto-generated method
stub
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method
stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method
stub
return 0;
}
@Override
public View getView(int position, View
convertView, ViewGroup parent) {
// TODO Auto-generated method
stub
ImageView imageView;
if (convertView == null)
{ // if it's not recycled, initialize
some attributes
imageView = new
ImageView(mContext);
imageView.setLayoutParams(new
GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8,
8);
} else {
imageView = (ImageView)
convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
}
package
com.example.dealrajudwidermawan_161011400142;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.Menu;
import
android.view.MenuItem;
import
android.widget.ImageView;
public class
SingleImage extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_image);
int imId =
this.getIntent().getExtras().getInt("posisi");
ImageView iv = (ImageView)
findViewById(R.id.singleimage);
int image =
ImageAdapter.mThumbIds[imId];
iv.setImageResource(image);
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this
adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.single_image,
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);
}
}
package
com.example.dealrajudwidermawan_161011400142;
import
android.app.Activity;
import
android.app.TabActivity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.Menu;
import
android.view.MenuItem;
import
android.widget.TabHost;
public class
TransportasiActivity extends TabActivity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transportasi);
Intent intent;
TabHost tabHost =
getTabHost();
TabHost.TabSpec spec;
intent = new
Intent().setClass(this, VipActivity.class);
spec = getTabHost().newTabSpec("Vip").setIndicator("Vip").setContent(intent);
tabHost.addTab(spec);
intent = new
Intent().setClass(this, BisnisActivity.class);
spec =
getTabHost().newTabSpec("Bisnis").setIndicator("Bisnis").setContent(intent);
tabHost.addTab(spec);
intent = new
Intent().setClass(this, EkonomiActivity.class);
spec =
getTabHost().newTabSpec("Ekonomi").setIndicator("Ekonomi").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.transportasi,
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);
}
}
package
com.example.dealrajudwidermawan_161011400142;
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
VipActivity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vip);
Button Pesawat =
(Button)findViewById(R.id.button1);
Pesawat.setOnClickListener(new
View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method
stub
Intent i = new
Intent(VipActivity.this, Pesawat2Activity.class);
i.putExtra("pesan",
"From Activity Main");
startActivity(i);
}
});
Button kapal =
(Button)findViewById(R.id.button2);
kapal.setOnClickListener(new
View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method
stub
Intent a = new
Intent(VipActivity.this, Kapal2Activity.class);
a.putExtra("pesan",
"From Activity Main");
startActivity(a);
}
});
Button kereta =
(Button)findViewById(R.id.button3);
kereta.setOnClickListener(new
View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method
stub
Intent j = new
Intent(VipActivity.this, Kereta2Activity.class);
j.putExtra("pesan",
"From Activity Main");
startActivity(j);
}
});
Button bus =
(Button)findViewById(R.id.button4);
bus.setOnClickListener(new
View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method
stub
Intent l = new
Intent(VipActivity.this, Bus2Activity.class);
l.putExtra("pesan",
"From Activity Main");
startActivity(l);
}
});
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this
adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.vip,
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);
}
}
9. BusActivity.java
package
com.example.dealrajudwidermawan_161011400142;
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
BusActivity extends Activity {
ListView LV;
String [] Menu =
{"Jogja","Malang","Bandung"};
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bus);
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) {
// TODO
Auto-generated method stub
String
Itemtext=(String) LV.getItemAtPosition(position);
if(Itemtext.equals("Jogja")){
Intent
jogja = new Intent(parent.getContext(),JogjaActivity.class);
startActivityForResult(jogja,0);;
}else
if(Itemtext.equals("Malang")){
Intent
Malang = new Intent(parent.getContext(),MalangActivity.class);
startActivityForResult(Malang,0);;
}else
if(Itemtext.equals("Bandung")){
Intent
Bandung = new Intent(parent.getContext(),BandungActivity.class);
startActivityForResult(Bandung,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.bus,
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);
}
}
10. CirebonActivity.java
package
com.example.dealrajudwidermawan_161011400142;
import
java.text.DecimalFormat;
import
java.text.NumberFormat;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.Menu;
import
android.view.MenuItem;
import
android.view.View;
import
android.widget.Button;
import
android.widget.EditText;
public class
CIrebonActivity extends Activity {
EditText jumlah,hasil;
Button total;
int jumlah_tiket,bayar,total_bayar;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cirebon);
jumlah =
(EditText)findViewById(R.id.editText4);
hasil =
(EditText)findViewById(R.id.editText5);
total =
(Button)findViewById(R.id.button1);
total.setOnClickListener(new
View.OnClickListener() {
@Override
public void
onClick(View arg0) {
// TODO
Auto-generated method stub
jumlah_tiket=Integer.parseInt(jumlah.getText().toString());
bayar=jumlah_tiket*500000;
NumberFormat
numberFormat = new DecimalFormat("#,###,###");
String str
= numberFormat.format(bayar);
hasil.setText("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);
}
}
BaliActivity.java
|
Bali1Activity.java
|
Bali2Activity.java
|
LampungActivity.java
|
Lampung1Activity.java
|
Lampung2Activity.java
|
MalangActivity.java
|
Malang1Activity.java
|
Malang2Activity.java
|
Bandung Activity.java
|
Bandung1 Activity.java
|
Bandung2 Activity.java
|
SurabayaActivity.java
|
Surabaya1Activity.java
|
Surabaya2Activity.java
|
LombokActivity.java
|
Lombok1Activity.java
|
Lombok2Activity.java
|
SoloActivity.java
|
Solo1 Activity.java
|
Solo2Activity.java
|
ManadoActivity.java
|
Manado1 Activity.java
|
Manado2Activity.java
|
MakassarActivity.java l
|
Makassar1Activity.java
|
Makassar2Activity.java
|
RajaActivity.java
|
Raja1Activity.java
|
Raja2Activity.java
|
JogjaActivity.java
|
Jogja1Activity.java
|
Jogja2Activity.java
|
|
Cirebon1Activity.java
|
Cirebon2Activity.java
|
9. 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.
10.Hasil Running
gambar diatas adalah apabila meklik button galery pada home tadi
gambar diatas apabila mengklik salah satu gambar
gambar diatas apabila klik button transaksi
gambar diatas klik salah satu dari button
gambar diatas form pembelian tiket travelnya
Apabila Setelah dirunning sesuai dengan gambar hasil Running diatas maka Aplikasi nya sukses.
Sekian pembahasan kali ini apabila cara menjelaskannya kurang baik. kurang lebihnya mohon maaf
Wassalamualaikum Wr.wb
Referensi :
https://www.codepolitan.com/bekerja-denga-imageview-599ab7a93d134
https://www.twoh.co/2013/04/13/tutorial-android-membuat-image-gallery-galeri-gambar-menggunakan-gridview/