Assalamu Alaikum Wr.Wb.
Pada tuturial kali ini kita akan membuat sebuah aplikasi dengan menu lengkap dengan map dan info detail.
Dalam pembuatan project ini dilengkapi dengan splash dan audio pada saat aplikasi sedang loading...
icon aplikasi
gambar splash
untuk file lagu.mp3 silahkan dicopy masuk ke dalam folder res/drawable-hdpi
1. Buat project (BelajarMap)
2. Pilih target device yang akan digunakan (mis. Android 2.2 Froyo)
3. Pilih compile APIs (karena kita menggunakan google map)
4. Ada beberapa activity yang akan kita buat, yaitu :
- main.xml
- splash.xml
- kategori.xml
- alam.xml
- kampus.xml
- rumah_sakit.xml
5. Adapun kode untuk main.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:orientation="vertical" > <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> </LinearLayout>
6. Adapun kode untuk splash.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="@drawable/sultan_hasanuddin" android:padding="15dp" > <ProgressBar android:id="@+id/ProgressBar01" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginTop="390sp" android:max="100" /> </LinearLayout>
7. Adapun kode untuk kategori.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:orientation="vertical" > <TextView android:id="@+id/TextView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/silahkan_pilih" android:textSize="20sp" android:textStyle="bold" > </TextView> <RadioGroup android:id="@+id/radGroupWisata" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radRekreasi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/wisata_rekreasi" > </RadioButton> <RadioButton android:id="@+id/radAlam" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/wisata_alam" > </RadioButton> <RadioButton android:id="@+id/radKampus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/kampus" > </RadioButton> <RadioButton android:id="@+id/radRS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/rumah_sakit" > </RadioButton> </RadioGroup> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/btnPilih" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="210sp" android:text="@string/pilih" android:textSize="20sp" android:width="160sp" > </Button> <Button android:id="@+id/btnExit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="210sp" android:text="@string/keluar" android:textSize="20sp" android:width="160sp" > </Button> </LinearLayout> </LinearLayout>
8. Adapun kode untuk alam.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:orientation="vertical" > <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> </LinearLayout>
9. Adapun kode untuk kampus.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:orientation="vertical" > <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> </LinearLayout>
10. Adapun kode untuk rumah_sakit.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:orientation="vertical" > <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> </LinearLayout>
11. Kemudian kita lanjut ke actionnya yaitu pada .java, ada beberapa yang akan kita buat :
- Main.java
- Splash.java
- Kategori.java
- TmptWst.java
- WisataAlam.java
- Kampus.java
- RumahSakit.java
12. Adapun kode untuk Main.java
package com.bas.belajarmap; import android.app.Activity; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundle; import android.os.Handler; import android.widget.ProgressBar; public class Main extends Activity { private int progress = 0; private int status = 0; ProgressBar progressBar; Handler handler = new Handler(); private MediaPlayer player; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); progressBar = (ProgressBar) findViewById(R.id.ProgressBar01); player = MediaPlayer.create(this, R.drawable.lagu); progressBar.setProgress(0); player.start(); new Thread(new Runnable() { public void run() { // TODO Auto-generated method stub while (status < 100) { status = loading(); handler.post(new Runnable() { public void run() { // TODO Auto-generated method stub progressBar.setProgress(status); } }); } handler.post(new Runnable() { public void run() { // TODO Auto-generated method stub Intent inten = new Intent(Main.this, Kategori.class); startActivity(inten); player.stop(); finish(); } }); } public int loading() { try { Thread.sleep(50); } catch (InterruptedException ie) { ie.printStackTrace(); } return progress++; } }).start(); } }
13. Adapun kode untuk Kategori.java
package com.bas.belajarmap; 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; import android.widget.RadioButton; import android.widget.RadioGroup; public class Kategori extends Activity { RadioGroup radGroupWisata; RadioButton radRekreasi; RadioButton radAlam; RadioButton radKampus; RadioButton radRS; Button btnPilih; Button btnExit; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.kategori); radGroupWisata = (RadioGroup) findViewById(R.id.radGroupWisata); radRekreasi = (RadioButton) findViewById (R.id.radRekreasi); radAlam = (RadioButton) findViewById (R.id.radAlam); radKampus = (RadioButton) findViewById (R.id.radKampus); radRS = (RadioButton) findViewById (R.id.radRS); btnPilih = (Button) findViewById (R.id.btnPilih); btnExit = (Button) findViewById (R.id.btnExit); btnPilih.setOnClickListener(new OnClickListener() { public void onClick (View v) { //int radioId = radGroupWisata.getCheckedRadioButtonId(); if(radRekreasi.isChecked()){ Intent rekreasi = new Intent(Kategori.this, TmptWst.class); startActivity(rekreasi); } if(radAlam.isChecked()){ Intent rekreasi = new Intent(Kategori.this, WisataAlam.class); startActivity(rekreasi); } if(radKampus.isChecked()){ Intent rekreasi = new Intent(Kategori.this, Kampus.class); startActivity(rekreasi); } if(radRS.isChecked()){ Intent rekreasi = new Intent(Kategori.this, RumahSakit.class); startActivity(rekreasi); } } }); btnExit.setOnClickListener(new OnClickListener() { public void onClick(View v){ AlertDialog aBox = createDialogBox(); aBox.show(); } }); } private AlertDialog createDialogBox(){ AlertDialog ab = new AlertDialog.Builder(this).setTitle("Apakah anda yakin ingin keluar?") .setPositiveButton("Ya", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { finish(); } }) .setNegativeButton("Tidak", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .create(); return ab; } }
14. Adapun kode untuk TmptWst.java
package com.bas.belajarmap; import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class TmptWst extends ListActivity { String[] nama = { "Pantai Losari", "Pulau Samalona", "Benteng Somba Opu","Fort Rotterdam" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, nama)); } public void onListItemClick(ListView parent, View v, int position, long id) { AlertDialog aBox = createDialogBox(position); aBox.show(); } private AlertDialog createDialogBox(final int position) { AlertDialog ab = new AlertDialog.Builder(this) .setTitle(nama[position]) // .setMessage("Choose one") .setPositiveButton("Map it", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { map(position); } }) .setNegativeButton("More Info", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { info(position); } }).create(); return ab; } private void map(int position) { if (position == 0) { // TODO Auto-generated method stub String myGeo = "geo:-5.14365,119.407486"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if (position == 1) { // TODO Auto-generated method stub String myGeo = "geo:-5.113889,119.400278"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if (position == 2) { // TODO Auto-generated method stub String myGeo = "geo:-5.133333,119.416667"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if (position == 3) { // TODO Auto-generated method stub String myGeo = "geo:-5.134146,119.405275"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } } private void info(int position) { if (position == 0) { String myWeb = "http://www.sulsel.go.id/wisata/Kota%20Makassar"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if (position == 1) { String myWeb = "http://www.sulsel.go.id/wisata/Kota%20Makassar"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if (position == 2) { String myWeb = "http://www.sulsel.go.id/wisata/Kota%20Makassar"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if (position == 3) { String myWeb = "http://www.sulsel.go.id/wisata/Kota%20Makassar"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } } }
15. Adapun kode untuk WisataAlam.java
package com.bas.belajarmap; import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class WisataAlam extends ListActivity { String[] nama = { "Hutan Kota Jompie", "Pantai Lumpue", "Pantai Cempae Sumur Jodoh", }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.alam); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, nama)); } public void onListItemClick( ListView parent, View v, int position, long id){ AlertDialog aBox = createDialogBox(position); aBox.show(); } private AlertDialog createDialogBox(final int position){ AlertDialog ab = new AlertDialog.Builder(this).setTitle(nama[position]) //.setMessage("Choose one") .setPositiveButton("Map it", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { map(position); } }) .setNegativeButton("More Info", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { info(position); } }) .create(); return ab; } private void map(int position){ if(position==0){ // TODO Auto-generated method stub String myGeo= "geo:-3.996681,119.641065"; Intent myIntent= new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if(position==1){ // TODO Auto-generated method stub String myGeo= "geo:-4.056807,119.622611"; Intent myIntent= new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if(position==2){ // TODO Auto-generated method stub String myGeo= "geo:-3.991203,119.633721"; Intent myIntent= new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } } private void info(int position){ if(position==0){ String myWeb= "http://www.sulsel.go.id/wisata/Kota%20Parepare"; Intent myIntent= new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if(position==1){ String myWeb= "http://www.sulsel.go.id/wisata/Kota%20Parepare"; Intent myIntent= new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if(position==2){ String myWeb= "http://www.sulsel.go.id/wisata/Kota%20Parepare"; Intent myIntent= new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } } }
16. Adapun kode untuk Kampus.java
package com.bas.belajarmap; import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class Kampus extends ListActivity { String[] nama = { "STMIK AKBA", "UNHAS", "STMIK Dipanegara", "UNM" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, nama)); } public void onListItemClick(ListView parent, View v, int position, long id) { AlertDialog aBox = createDialogBox(position); aBox.show(); } private AlertDialog createDialogBox(final int position) { AlertDialog ab = new AlertDialog.Builder(this) .setTitle(nama[position]) // .setMessage("Choose one") .setPositiveButton("Map it", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { map(position); } }) .setNegativeButton("More Info", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { info(position); } }).create(); return ab; } private void map(int position) { if (position == 0) { // TODO Auto-generated method stub String myGeo = "geo:-5.141592,119.484673"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if (position == 1) { // TODO Auto-generated method stub String myGeo = "geo:-5.140724,119.488581"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if (position == 2) { // TODO Auto-generated method stub String myGeo = "geo:-5.141235,119.483405"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if (position == 3) { // TODO Auto-generated method stub String myGeo = "geo:-5.169294,119.43619"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } } private void info(int position) { if (position == 0) { String myWeb = "http://www.akba.ac.id/site"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if (position == 1) { String myWeb = "http://www.unhas.ac.id/"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if (position == 2) { String myWeb = "http://www.dipanegara.ac.id/"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if (position == 3) { String myWeb = "http://www.unm.ac.id/"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } } }
17. Adapun kode untuk RumahSakit.java
package com.bas.belajarmap; import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class RumahSakit extends ListActivity { String[] nama = { "RS Pelamoniah", "RS Bersalin Gracia Daya","RS Ibu dan Anak Pertiwi" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, nama)); } public void onListItemClick(ListView parent, View v, int position, long id) { AlertDialog aBox = createDialogBox(position); aBox.show(); } private AlertDialog createDialogBox(final int position) { AlertDialog ab = new AlertDialog.Builder(this) .setTitle(nama[position]) // .setMessage("Choose one") .setPositiveButton("Map it", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { map(position); } }) .setNegativeButton("More Info", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { info(position); } }).create(); return ab; } private void map(int position) { if (position == 0) { // TODO Auto-generated method stub String myGeo = "geo:-5.137774,119.41496"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } else if (position == 1) { // TODO Auto-generated method stub String myGeo = "geo:-5.120014,119.510533"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); }else if (position == 2) { // TODO Auto-generated method stub String myGeo = "geo:-5.140369,119.413968"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myGeo)); startActivity(myIntent); } } private void info(int position) { if (position == 0) { String myWeb = "http://telpon.info/rumah-sakit/makassar/"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if (position == 1) { String myWeb = "http://telpon.info/rumah-sakit/makassar/"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } else if (position == 2) { String myWeb = "http://telpon.info/rumah-sakit/makassar/"; Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myWeb)); startActivity(myIntent); } } }
18. Kemudian pada bagian AndroidManifest dengan kode berikut :
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.bas.belajarmap" android:versionCode="1" android:versionName="1.0" > <application android:icon="@drawable/sultan_hasanuddin" android:label="@string/app_name" > <activity android:name=".Main" android:label="@string/app_name" android:theme="@android:style/Theme.Light" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Kategori" > </activity> <activity android:name=".TmptWst" > </activity> <activity android:name=".WisataAlam" > </activity> <activity android:name=".Kampus" > </activity> <activity android:name=".RumahSakit" > </activity> </application> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" /> </manifest>
19. Run project (Ctrl + F11)
Silahkan dikembangkan........
Belajar dan berbagi bersama..... :)
Tutarni : Terima kasih atas tutorial yang sangat bermanfaat, saya akan mencoba semoga berhasil, mohon dibanyakin lagi tutorialnya ya...
ReplyDeletesama" n tutorial yang saya buat ini sebagai bahan latihan pada saat pembuatan skripsi tahun 2013
Deleteelamat pagi numpang promo yah admin
ReplyDeleteServer boleh sama, tetapi E D E N POKER memberikan sensasi yang berbeda dan juga pelayanan yang tercepat & terbaik.
yuk tunggu apa lagi segera join bersama kami!
GUDANG PROMO IDN POKER
Agen Bandar Poker Terpercaya
Bandar Poker IDN
Poker IDN Terbaik
Agen Judi Uang Asli
Agen Judi Terbaik Di Indonesia
Agen Judi Deposit Murah
Info Poker IDN Terbaik