Percobaan 1: Menggunakan Spin Control

Workshop Struktur dan Pemakaian Teknologi Game 59 Workshop 4 Selection Widget

A. Tujuan

1. Memahami penggunaan dari Selection Widget

B. Tugas Pendahuluan

1. Pelajari Selection Widget Android

C. Percobaan

a. Percobaan 1: Menggunakan Spin Control

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 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 Workshop Struktur dan Pemakaian Teknologi Game 60 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 }; 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; } 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