20.03.2018 Views

52405e6d24ca124JAM-Pintar-Pemrograman-Android-1

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

24 JAM!! <strong>Pintar</strong> <strong>Pemrograman</strong> <strong>Android</strong><br />

14: android:text="TextView"<br />

15: android:layout_height="wrap_content"<br />

16: android:id="@+id/hasil"><br />

17: <br />

4. Ketiklah script AutocompleteSederhana.java seperti<br />

berikut<br />

1: package com.auto.comp;<br />

2:<br />

3: import android.app.Activity;<br />

4: import android.os.Bundle;<br />

5: import android.text.Editable;<br />

6: import android.text.TextWatcher;<br />

7: import android.widget.ArrayAdapter;<br />

8: import android.widget.AutoCompleteTextView;<br />

9: import android.widget.TextView;<br />

10:<br />

11: public class AutocompleteSederhana extends Activity implements<br />

TextWatcher {<br />

12: /** Called when the activity is first created. */<br />

13: TextView hasil;<br />

14: AutoCompleteTextView edit;<br />

15: String[] item = { "Merbabu", "Merapi", "Lawu", "Rinjani",<br />

16: "Sumbing","Sindoro", "Krakatau", "Selat Sunda", "Selat<br />

17: Bali","Selat Malaka","Kalimantan", "Sulawesi", "Jawa" };<br />

18:<br />

19: @Override<br />

20: public void onCreate(Bundle savedInstanceState) {<br />

21: super.onCreate(savedInstanceState);<br />

22: setContentView(R.layout.main);<br />

23:<br />

24: hasil = (TextView) findViewById(R.id.hasil);<br />

25: edit = (AutoCompleteTextView) findViewById(R.id.edit);<br />

26: edit.addTextChangedListener(this);<br />

27: edit.setAdapter(new ArrayAdapter(this,<br />

28: android.R.layout.simple_dropdown_item_1line, item));<br />

29: }<br />

30:<br />

31: public void onTextChanged(CharSequence s, int start, int<br />

32: before, int count) {<br />

33: hasil.setText(edit.getText());<br />

34: }<br />

35:<br />

36: public void beforeTextChanged(CharSequence s, int start, int<br />

37: count, int after) {<br />

38: // not used<br />

39: }<br />

40:<br />

41: public void afterTextChanged(Editable s) {<br />

42: // not used<br />

43: }<br />

44: }<br />

Bila script berantakan, lakukan Format (source > format).<br />

Lakukan RUN dan lihat hasilnya.<br />

Dapatkan materi terbaru di<br />

www.omayib.com<br />

40

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!