AutoCompleteTextView实现自动搜索

2018-01-12  本文已影响0人  小毕_先生

一,布局
//android:completionThreshold="1" //表示输入一个字母就开始搜索

<AutoCompleteTextView
android:completionThreshold="1"
android:hint="请输入需要搜索的内容"
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

二,代码

  //EditText米有setAdapter()方法
    AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
    ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            result_arr);
    autoCompleteTextView.setAdapter(stringArrayAdapter);
上一篇 下一篇

猜你喜欢

热点阅读