AutoCompleteTextView in Android
AutoCompleteTextView is an editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.
main.xml
<?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" > <AutoCompleteTextView android:id="@+id/myautocomplete" android:layout_width="fill_parent" android:layout_height="wrap_content" android:completionThreshold="1" /> </LinearLayout> |
AutoCompleteExampleActivity.java
package com.example.autocomplete; import android.app.Activity; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class AutoCompleteExampleActivity extends Activity implements TextWatcher { String item[]={ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; AutoCompleteTextView myAutoComplete; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myAutoComplete = (AutoCompleteTextView)findViewById(R.id.myautocomplete); myAutoComplete.addTextChangedListener(this); myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, item)); } public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } } |
Comments
Post a Comment