2. MainActivity.java
package org.me.android_autocompletetextview; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class MainActivity extends Activity { private AutoCompleteTextView autoComplete; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete); String[] phone = new String[]{"0986254878","0985225787","098525879","0985012486","0985658745"}; //設定自動填入的文字內容 ArrayAdapteradapter = new ArrayAdapter (this,android.R.layout.simple_spinner_item,phone); autoComplete.setAdapter(adapter); } }
3. main.xml(Layout)
<?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/autoComplete" android:layout_width="fill_parent" android:layout_height="50px"> </AutoCompleteTextView> </LinearLayout>
4. 在「自動填入文字框」輸入文字之後出現的畫面。
沒有留言:
張貼留言