代碼比較簡單就不多說了,里面有注釋:
首先是在布局中加入AutoCompleteTextView
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/activity_main"android:layout_width="match_parent"android:layout_height="match_parent" ><AutoCompleteTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/auto_complete"/></LinearLayout>然后
public class MainActivity extends AppCompatActivity { //定義AutoCompleteTextView對象 PRivate AutoCompleteTextView autoText; //模擬數據,實際應用會從網絡或數據庫獲取數據 public String[]texts={"text","t最后,當你輸入一個字母查詢量會比較大。所以會設置android:completionThreshold屬性,當用戶輸入一定量的字母之后才會進行補全。源碼下載 更多學習筆記請訪問:www.xiaob.tech
新聞熱點
疑難解答