0
時需要額外的佈局檢查代碼在http://developer.android.com/resources/tutorials/views/hello-autocomplete.html 或爲什麼我們使用AutoCompleteTextView
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#000">
</TextView>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Country" />
<AutoCompleteTextView android:id="@+id/autocomplete_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"/>
</LinearLayout>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
textView.setAdapter(adapter);
}
,然後我們有一個靜態最後絃樂[中]國家充滿了所有國家。
我的問題是爲什麼我們使用list_item.xml。實際上list_item.xml包含代碼的第一部分,第二個xml代碼用於main.xml,然後是活動的java代碼
u是指當我輸入幾個字母組成的實際是佈局的項目(list_item)時,我得到的autocompletetextview下拉框。 – Housefly 2012-04-06 10:03:46
是的。如果你不想創建自己的佈局,實際上內置的佈局可以使用。最受歡迎的是android.R.layout.simple_list_item_1 – 2012-04-06 10:06:12
非常感謝您。 – Housefly 2012-04-06 10:09:24