Page 40 - 24JAM_Pintar_Pemrograman_Android__1-libre
P. 40

  24 JAM!! Pintar Pemrograman Android
            14:            android:text="TextView"
            15:            android:layout_height="wrap_content"
            16:            android:id="@+id/hasil"></TextView>
            17:  </LinearLayout>

                4.  Ketiklah  script  AutocompleteSederhana.java  seperti
                    berikut
            1:  package com.auto.comp;
            2:
            3:  import android.app.Activity;
            4:  import android.os.Bundle;
            5:  import android.text.Editable;
            6:  import android.text.TextWatcher;
            7:  import android.widget.ArrayAdapter;
            8:  import android.widget.AutoCompleteTextView;
            9:  import android.widget.TextView;
            10:
            11:  public class AutocompleteSederhana extends Activity implements
                TextWatcher {
            12:     /** Called when the activity is first created. */
            13:     TextView hasil;
            14:     AutoCompleteTextView edit;
            15:     String[] item = { "Merbabu", "Merapi", "Lawu", "Rinjani",
            16:      "Sumbing","Sindoro", "Krakatau", "Selat Sunda", "Selat
            17:       Bali","Selat Malaka","Kalimantan", "Sulawesi", "Jawa" };
            18:
            19:     @Override
            20:     public void onCreate(Bundle savedInstanceState) {
            21:     super.onCreate(savedInstanceState);
            22:     setContentView(R.layout.main);
            23:
            24:     hasil = (TextView) findViewById(R.id.hasil);
            25:     edit = (AutoCompleteTextView) findViewById(R.id.edit);
            26:     edit.addTextChangedListener(this);
            27:     edit.setAdapter(new ArrayAdapter<String>(this,
            28:            android.R.layout.simple_dropdown_item_1line, item));
            29:     }
            30:
            31:      public void onTextChanged(CharSequence s, int start, int
            32:      before, int count) {
            33:            hasil.setText(edit.getText());
            34:     }
            35:
            36:     public void beforeTextChanged(CharSequence s, int start, int
            37:      count, int after) {
            38:            // not used
            39:     }
            40:
            41:     public void afterTextChanged(Editable s) {
            42:            // not used
            43:     }
            44:  }

            Bila script berantakan, lakukan Format (source > format).
            Lakukan RUN dan lihat hasilnya.

                              Dapatkan materi terbaru di                   40
                                       www.omayib.com
   35   36   37   38   39   40   41   42   43   44   45