我想在android中使用AutoCompleteTextView並閱讀關於它的官方developer.android文檔。我不明白Android的AutoCompleteTextView ArrayAdapter的構造函數
有一個代碼片段,它看起來像:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
我不明白是什麼在ArrayAdapter的構造函數的第二個參數(android.R.layout.simple_dropdown_item_1line)意味着,哪裏該來從?
它是從android可用的佈局還是我必須用我自己創建的佈局替換此佈局以及如何在此情況下定義此佈局文件?
混凝土我的代碼lokks像 XML:
<AutoCompleteTextView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
的java:
AutoCompleteTextView search =(AutoCompleteTextView) findViewById(R.id.search);
String[] vocabs = new String[1001];
//fill the String array
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line ,vocabs);
search.setAdapter(adapter);
無需更換它,它是每一行的默認佈局我在您的自動完成視圖中,或者如果您需要自定義佈局,則可以更改此設置 –