5
我在嘗試使用和ArrayAdapter動態更新AutocompleteTextView的列表。爲了更新此視圖,我使用TextWatcher來監視AutocompleteTextView中可能發生的任何更改。帶有ArrayAdapter和TextWatcher的動態AutocompleteTextView
問題是,列表並沒有更新,我不明白爲什麼。我一直在尋找類似於互聯網的東西,我已經找到了幾種不同的方法,但我仍然不明白爲什麼這個應該是最簡單的方法不起作用。任何解釋將不勝感激。
目標AVD:谷歌API的10級的Android 2.3.3
下面是簡化的代碼:
public class AutocompleteActivity extends Activity implements TextWatcher {
ArrayAdapter<String> adapter = null;
AutoCompleteTextView acTextView = null;
ArrayList<String> addresses = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.autocompleteview);
acTextView = (AutoCompleteTextView) findViewById(R.id.autocomplete_address);
adapter = new ArrayAdapter<String>(this, R.layout.listitem, addresses);
adapter.setNotifyOnChange(true);
acTextView.addTextChangedListener(this);
acTextView.setAdapter(adapter);
}
@Override
public void onTextChanged(CharSequence text, int start, int before, int after) {
try {
adapter.add("test");
}
catch (Exception e) {
e.printStackTrace();
}
}
nvm,它的工作原理:-( – gioski
我在這裏做類似的事情!!! http://stackoverflow.com/questions/12854336/autocompletetextview-backed-by-cursorloader – toobsco42