Android AutoCompleteTextView连接数据库自动提示的方法(附demo源码下载

2019-12-10 19:07:05王振洲

3、最后定义View

<AutoCompleteTextView
    android:id="@+id/autoCompleteTextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text=""
    android:hint="@string/dbAutoComlete" >
    <requestFocus />
</AutoCompleteTextView>

4、在Activity中关联View和Adapter

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    AutoCompleteAdatercursorAdapter = new AutoCompleteAdater(this, android.R.layout.simple_dropdown_item_1line,null, DBHelper.NAME, android.R.id.text1);
    // 设置输入一个字符就弹出提示列表(默认输入两个字符时才弹出提示)
    ((AutoCompleteTextView) this.findViewById(R.id.autoCompleteTextView1)).setThreshold(1);
    ((AutoCompleteTextView) this.findViewById(R.id.autoCompleteTextView1)).setAdapter(cursorAdapter);
}

Android AutoCompleteTextView连接数据库自动提示的方法(附demo源码下载)

完整实例代码点击此处本站下载。



注:相关教程知识阅读请移步到Android开发频道。