You are on page 1of 3

<?xml version="1.0" encoding="utf-8"?

>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:text="@string/perintah"
/>
<AutoCompleteTextView
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="3"
/>
<TextView
android:layout_width="fill_parent"
android:text="@string/tv"
android:layout_height="wrap_content"
android:id="@+id/hasil"
/>
</LinearLayout>
package com.auto.comp;
import android.app.Activity;
import android.os.Bundle;
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 hasil;
AutoCompleteTextView edit;
String[] item= {"merbabu",
"lawu",
"rinjani",
"sumbing",
"sindoro",
"krakatau",
"selat sundah",
"selat bali",
"selat malaka",
"kalimantan",
"jawa" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hasil=(TextView) findViewById(R.id.hasil);
edit=(AutoCompleteTextView) findViewById(R.id.edit);
edit.addTextChangedListener(this) ;
edit.setAdapter (new ArrayAdapter<String>(this,android.R.layout.
simple_dropdown_item_1line,item));
}
public void onTextChanged(CharSequence s,int start, int before, int
count) {
hasil.setText(edit.getText());
}
public void beforeTextChanged(CharSequence s,int start, int before, int
after) {
}
public void afterTextChanged(Editable s) {
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AutoCompleteSederhana</string>
<string name="action_settings">Settings</string>
<string name="perintah">masukan minimal 3 huruf</string>
<string name="tv">hasil</string>
</resources>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"/>
</menu>

You might also like