需要帮助AutoCompleteTextView进行搜索

Sen*_* Mg 2 android

我已经实现了AutoCompleteTextView搜索.是AutoCompleteTextView支持所有SDK版本和目标,因为当我尝试这样做的样品 是显示一个空的下拉列表.当我在我的应用程序中使用相同的解析内容放置在字符串数组中时,我得到一个例外.

Log.v("Length of a",Integer.toString(a.length));
try{
    wv.setVisibility(View.GONE);
    place_list.setVisibility(View.VISIBLE);
    Log.v("Length of a222222",Integer.toString(a.length));

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(Bru_Maps.this, android.R.layout.simple_dropdown_item_1line, a);
    textView.setAdapter(adapter);
} catch(Exception e) {                  
    Log.v("Error","search_name"+e);     
}
Run Code Online (Sandbox Code Playgroud)

上面给出的代码打印日志很好,但它返回一个NullPointerException.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(Bru_Maps.this, android.R.layout.simple_dropdown_item_1line, a);
Run Code Online (Sandbox Code Playgroud)

Rag*_*har 5

正如我在示例中看到的那样,如果要在TextView中键入第一个字符后查看可用国家/地区列表,则需要将"阈值"值设置为1.用autoCompleteTextView.setThreshold(1)看到它在行动.