初対面AutoCompleteTextView
2527 ワード
AutoCompleteTextView自動補完ボックスはTextViewとEditViewから継承され、ドロップダウンボックスの形式で情報を補完できます.
setThreshold()メソッドでは、ユーザーが何文字を入力したかを指定して、推奨情報を携帯するドロップダウン・ボックスの表示を開始できます.
データ・ソースの設定とアダプタの追加
setThreshold()メソッドでは、ユーザーが何文字を入力したかを指定して、推奨情報を携帯するドロップダウン・ボックスの表示を開始できます.
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="AutoCompleteTextView" />
データ・ソースの設定とアダプタの追加
1 private void showAutoCompleteTextView() {
2
3 autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
4 /*
5 adapter
6 adapter UI
7 */
8 String[] countriesStrings = getResources().getStringArray(R.array.countries_array);
9 ArrayAdapter<String> countryListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,countriesStrings);
10 autoCompleteTextView.setAdapter(countryListAdapter);
11 }