2010-10-25 95 views
2

我已經實施AutoCompleteTextView搜索。所有SDK版本和目標都支持AutoCompleteTextView,因爲當我嘗試這sample 它顯示一個空的下拉列表。當我在我的應用程序中使用相同的解析內容放置在一個字符串數組中時,我得到一個異常。需要幫助AutoCompleteTextView搜索

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);  
} 

上面給出的代碼很好地打印日誌,但它返回NullPointerException

ArrayAdapter<String> adapter = new ArrayAdapter<String>(Bru_Maps.this, android.R.layout.simple_dropdown_item_1line, a); 

回答

5

從示例中可以看出,如果希望在TextView中鍵入第一個字符後查看可用國家/地區列表,則需要將閾值設置爲1。使用autoCompleteTextView.setThreshold(1)即可看到它的行動。

+0

感謝老兄..我明白了 – 2010-10-26 09:18:43

0

不能添加評論,所以...什麼是一個數據類型?你寫道它是一個字符串,當它需要是一個字符串數組