標籤:http create draw code ima super array opd hint
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:orientation="vertical" 5 android:layout_height="match_parent" 6 tools:context="com.example.top5_1.MainActivity" > 7 8 <EditText 9 android:layout_width="fill_parent"10 android:layout_height="wrap_content"11 android:paddingLeft="5dp"12 android:background="#FFA500"13 android:textSize="16sp"14 android:drawableLeft="@drawable/ic_launcher"15 android:text="單詞搜尋補全示範" />16 <AutoCompleteTextView17 android:id="@+id/ed"18 android:layout_width="fill_parent"19 android:layout_height="wrap_content"20 style="@android:attr/textViewStyle"21 android:hint="請輸入單詞"
//設定從第二個字元開始提示22 android:completionThreshold="2"23 android:layout_marginTop="10dp"24 25 /></LinearLayout>
JAVA:
1 public class MainActivity extends Activity{ 2 private AutoCompleteTextView act; 3 //設定資料來源 4 private static final String[] words={"abc","acd","ade"}; 5 6 protected void onCreate(Bundle savedInstanceState) { 7 super.onCreate(savedInstanceState); 8 setContentView(R.layout.activity_main); 9 act=(AutoCompleteTextView) findViewById(R.id.ed);10 //將資料來源賦到文字框11 ArrayAdapter<String> aa=new ArrayAdapter<String>(this,12 android.R.layout.simple_dropdown_item_1line,words);13 act.setAdapter(aa);14 };
Android基礎TOP5_1:AutoCompleteTextView自動補全文字框