Workshop Struktur dan Pemakaian Teknologi Game
61
public void
beforeTextChangedCharSequence s, int
start, int
count,
int after{
needed for interface but unused }
public void
afterTextChangedEditable e{ needed for interface but unused
} }
Langkah 4: Tekan F11 untuk mendebug aplikasi pada emulator Android Langkah 5: Kemudian, akan muncul output sebagai berikut :
Gambar 21 Contoh Tampilan Selection Widget
b. Percobaan 2: Menggunakan AutoCompleteTextView
Langkah 1: Buat project Android baru pada Eclipse Langkah 2: Ketikan kode berikut pada main.xml
RelativeLayout xmlns:android
= http:schemas.android.comapkresandroid
xmlns:tools =
http:schemas.android.comtools android:layout_width
= match_parent
android:layout_height =
match_parent
Workshop Struktur dan Pemakaian Teknologi Game
62
tools:context =
.MainActivity android:background
= 000000
TextView android:id
= +idselect
android:layout_width =
fill_parent android:layout_height
= wrap_content
android:textSize =
14pt android:textStyle
= bold
android:textColor =
000000 android:background
= 0000fftes
AutoCompleteTextView android:id
= +idedit
android:layout_width =
fill_parent android:layout_height
= wrap_content
android:layout_alignParentLeft =
true android:layout_below
= +idselect
android:completionThreshold =
3 android:ems
= 10
android:textColor =
ff0000 requestFocus
AutoCompleteTextView RelativeLayout
Langkah 3 : Pada MainActivity.java ketikkan kode berikut ini :
package com.example.selectionwidget2;
import
android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.text.Editable;
import android.text.TextWatcher;
import
android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
public class
MainActivity extends
Activity implements
TextWatcher{ TextView
selection ;
AutoCompleteTextView edit
; String[]
items = {
this ,
is ,
a ,
test1 ,
test2 ,
test3 ,
test4 ,
test5 ,
test ,
list };
Workshop Struktur dan Pemakaian Teknologi Game
63
Override
public void
onCreateBundle icicle {
super .onCreateicicle;
setContentViewR.layout. main
; selection
= TextView findViewByIdR.id. select
; edit
= AutoCompleteTextViewfindViewByIdR.id. edit
; edit
.addTextChangedListener this
; edit
.setAdapter new
ArrayAdapterString this
, android.R.layout.
simple_dropdown_item_1line ,
items ;
}
public void
onTextChangedCharSequence s,
int
start,
int
before,
int
count{ selection
.setText edit
.getText; }
public void
beforeTextChangedCharSequence s,
int
start,
int
count,
int after{
needed for interface but unused }
public void
afterTextChangedEditable e{ needed for interface but unused
} }
Langkah 4: Tekan F11 untuk mendebug aplikasi pada emulator Android Langkah 5: Kemudian, akan muncul output sebagai berikut :
Gambar 22 Contoh Tampilan Selection Widget
Workshop Struktur dan Pemakaian Teknologi Game
64 Langkah 6 : Isikan edit text yang tersedia, misalnya, ketikkan “test”. Maka akan
muncul AutoCompleteTextView seperti gambar bawah ini :
Gambar 23 Contoh Tampilan AutoCompleteTextView
c. Percobaan 3: Membuat Date and Time Selection Widget