Percobaan 2: Membuat Contoh Aplikasi BMI Body Mass Index

Workshop Struktur dan Pemakaian Teknologi Game 115 Langkah 7 : Coba untuk klik pada button [Go To Child] yang akan meng-intent ke activity kedua, maka akan muncul output sebagai berikut : Gambar 42 Tampilan Child Activity

b. Percobaan 2: Membuat Contoh Aplikasi BMI Body Mass Index

Langkah 1: Buat project Android baru pada Eclipse Langkah 2: Tambahkan statement berikut pada main.xml ? xml version = 1.0 encoding = utf-8 ? LinearLayout xmlns:android = http:schemas.android.comapkresandroid android:layout_width = fill_parent android:layout_height = fill_parent android:orientation = vertical TextView android:id = +idlbltitle android:layout_width = wrap_content android:layout_height = wrap_content android:text = CEK BMI ANDA android:textStyle = bold android:textColor = ffcc0000 android:textSize = 20px android:layout_gravity = center_horizontal TextView android:layout_width = fill_parent android:layout_height = wrap_content android:textSize = 20px Workshop Struktur dan Pemakaian Teknologi Game 116 TextView android:layout_width = fill_parent android:layout_height = wrap_content android:text = Masukkan berat badankg : EditText android:id = +idbb android:layout_width = fill_parent android:layout_height = wrap_content EditText TextView android:text = Masukkan tinggi badanm : android:id = +idTextView01 android:layout_width = wrap_content android:layout_height = wrap_content TextView EditText android:id = +idtb android:layout_width = fill_parent android:layout_height = wrap_content EditText Button android:text = Hitung android:id = +idhitung android:layout_width = wrap_content android:layout_height = wrap_content Button LinearLayout Langkah 3: Buatlah sebuah file XML baru, beri nama hasil.xml : ? xml version = 1.0 encoding = utf-8 ? LinearLayout xmlns:android = http:schemas.android.comapkresandroid android:layout_width = match_parent android:layout_height = match_parent android:orientation = vertical TextView android:id = +idlblbolide android:layout_width = wrap_content android:layout_height = wrap_content android:text = HASIL BMI ANDA android:textStyle = bold android:textColor = ff00cc android:layout_gravity = center_horizontal TextView TextView android:layout_width = wrap_content Workshop Struktur dan Pemakaian Teknologi Game 117 android:layout_height = wrap_content android:textSize = 20px TextView TextView android:layout_width = fill_parent android:layout_height = wrap_content android:textSize = 20px android:background = ff00cc android:text = Hasil : android:textStyle = bold TextView TextView android:id = +idhslAngka android:layout_width = wrap_content android:layout_height = wrap_content TextView TextView android:layout_width = wrap_content android:layout_height = wrap_content android:textSize = 20px TextView TextView android:background = ff00cc android:text = Kategori android:textStyle = bold android:id = +idkategori android:layout_width = fill_parent android:layout_height = wrap_content TextView TextView android:id = +idhslKategori android:layout_width = wrap_content android:layout_height = wrap_content TextView LinearLayout Langkah 4 : Lengkapi statement berikut pada class MainActivity : package com.ai.intent; import java.security.PublicKey; import android.app.Activity; import android.content.Intent; import android.graphics.Typeface; import android.net.Uri; Workshop Struktur dan Pemakaian Teknologi Game 118 import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.view.View.OnClickListener; public class IntentBMIActivity extends Activity { EditText beratbadan ; EditText tinggibadan ; TextView hasil , angka ; Button btnHitung ; Float berat , tinggi , hsl ; Override public void onCreateBundle savedInstanceState { super .onCreatesavedInstanceState; setContentViewR.layout. main ; beratbadan =EditTextfindViewByIdR.id. bb ; tinggibadan =EditTextfindViewByIdR.id. tb ; btnHitung =ButtonfindViewByIdR.id. hitung ; btnHitung .setOnClickListener new OnClickListener { public void onClickView v { itung beratbadan .getText.toString, tinggibadan .getText.toString; callIntentv; } }; } public void callIntent View v{ Intent i = new IntentIntentBMIActivity. this ,hitungBMI. class ; i.putExtra hasil , hsl ; startActivityi; } public void itungString b, String t{ berat = Float.parseFloat beratbadan .getText.toString; tinggi = Float.parseFloat tinggibadan .getText.toString; hsl = berat tinggi tinggi ; } } Workshop Struktur dan Pemakaian Teknologi Game 119 Langkah 5 : Kemudian, buatlah sebuah activity lagi, untuk menampilkan hasil hitung activity pertama, berikut adalah kodingnya : package com.ai.intent; import android.widget.EditText; import android.widget.TextView; import android.app.Activity; import android.graphics.Typeface; import android.os.Bundle; import android.view.View; public class hitungBMI extends Activity { Float hsl ; TextView hasil , angka , title2 ; public void onCreateBundle savedInstanceState{ super .onCreatesavedInstanceState; setContentViewR.layout. hasil ; TextView title2=TextViewfindViewByIdR.id. lblbolide ; Typeface myfont2=Typeface.createFromAssetgetAssets, fontsPoloBrush.ttf ; title2.setTypefacemyfont2; hasil =TextViewfindViewByIdR.id. hslKategori ; angka =TextViewfindViewByIdR.id. hslAngka ; Bundle bundle = getIntent.getExtras; Intent i = this.getIntent; float hsl=bundle.getFloat hasil ; if hsl18.5{ angka .setText +hsl; hasil .setText UNDERWEIGHT ; } else if hsl=18.5 hsl24.99{ hasil .setText NORMAL ; angka .setText +hsl; } else if hsl=25 hsl29.99{ hasil .setText OVERWEIGHT ; angka .setText +hsl; } else if hsl=30{ hasil .setText OBESITAS ; angka .setText +hsl; } } } Workshop Struktur dan Pemakaian Teknologi Game 120 Langkah 6 : Pada AndroidManifest.xml perhatikan setiap baris kodenya sebagai berikut : ? xml version = 1.0 encoding = utf-8 ? manifest xmlns:android = http:schemas.android.comapkresandroid package = com.ai.intent android:versionCode = 1 android:versionName = 1.0 uses-sdk android:minSdkVersion = 10 application android:icon = drawableic_launcher android:label = stringapp_name activity android:name = .IntentBMIActivity android:label = stringapp_name intent-filter action android:name = android.intent.action.MAIN category android:name = android.intent.category.LAUNCHER intent-filter activity activity android:label = HitungBMI android:name = .hitungBMI activity application manifest Langkah 5 : Tekan F11 untuk mendebug aplikasi pada emulator Android Langkah 6 : Maka akan muncul output awal sebagai berikut : Workshop Struktur dan Pemakaian Teknologi Game 121 Gambar 43 Tampilan Awal BMI Langkah 7 : Isikan data-data pada text box, kemudian klik button [Hitung], maka akan menghubungkan ke activity kedua sebagai berikut Gambar 44 Tampilan Perhitungan BMI Workshop Struktur dan Pemakaian Teknologi Game 122

c. Percobaan 3: Membuat Contoh Kurs Dollar ke Rupiah