android自帶記錄功能的輸入框AutoCompleteTextView
阿新 • • 發佈:2019-01-30
使用環境:
需要用到提醒輸入功能的輸入框時使用
使用效果:
使用方法:
AutoCompleteTextView
1 xml佈局:
<AutoCompleteTextView android:id="@+id/search" android:layout_width="@dimen/threehundred" android:layout_height="@dimen/thirtyfive" android:layout_marginLeft="@dimen/eight" android:layout_marginTop="@dimen/twenty" android:background="@drawable/draw_fragment_message_vin" android:drawablePadding="8dp" android:hint="@string/input_search_info_vin" android:inputType="text" android:maxLength="17" android:maxLines="1" android:completionThreshold="1" android:paddingLeft="@dimen/fifteen" android:textColor="@color/tv_1" android:textColorHint="@color/tv_3" android:textSize="@dimen/textsize12" />
android:completionThreshold="1"意思: 輸入一個字元就開始做篩選
2 程式碼中呼叫:
String[] autoString = new String[]{"LGBG22E00EY201241", "LGBG22E00EY201242", "LGBG22E00EY201243", "LGBG22E00EY201244", "LGBG22E00EY201245", "LGBG22E00EY201246", "LGBG22E00EY201247", "LGBG22E00EY201248", "LGBG22E00EY201249"}; ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.simple_dropdown_item_1line, autoString); binding.search.setAdapter(adapter);
MultiAutoCompleteTextView
支援多個關鍵詞,用“ , ” 隔開搜尋的輸入框:
<MultiAutoCompleteTextView
android:id="@+id/multiAutoCompleteTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
程式碼中呼叫與上邊一樣即可。
有問題需要討論請加QQ: 88627109
歡迎您的光臨