APIからデータ(List
)を取得していますが、このデータでAutcompleteTextView
を更新しようとしています。AutocompleteTextViewが動的に更新されない
これは私が現在行う方法です。
私は、ユーザーがメソッドを入力して停止するたびに呼び出され、アダプターが `` notifyDataSetChangedで通知され、afterTextChanged
にデータを取得するためのメソッドを呼び出しTextWatcher
を持っています:
//in onCreate
addressAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,suggestions_address);
at_address.setAdapter(addressAdapter);
...
@Override
public void afterTextChanged(Editable s) {
autoComplete(s);
addressAdapter.notifyDataSetChanged();
//suggestions_address is the updated list, and when I print it I can see the
//results so it is not empty
Log.i("addresses",suggestions_address.toString());
}
...
class SuggestionQueryListener implements ResultListener<List<String>> {
@Override
public void onCompleted(List<String> data, ErrorCode error) {
if (error != ErrorCode.NONE) {
Toast.makeText(MainActivity2.this,error.toString(),Toast.LENGTH_LONG).show();
} else {
suggestions_address.clear();
for(int i = 0;i<data.size();i++){
suggestions_address.add(data.get(i));
}
}
}
}
public void autoComplete(CharSequence s) {
try {
String term = s.toString();
TextSuggestionRequest request = null;
request = new TextSuggestionRequest(term).setSearchCenter(new GeoCoordinate(48.844900, 2.395658));
request.execute(new SuggestionQueryListener());
if (request.execute(new SuggestionQueryListener()) != ErrorCode.NONE) {
//Handle request error
//...
}
} catch (IllegalArgumentException ex) {
//
}
}
しかし、アダプターは実際に更新されていないようですが、何か入力するとその提案が表示されないようです。
AutoCompleteTextView
でこれを行う前に、私は同じプロセスでlistView
でそれを行い、すべてがうまくいきました。
任意のアイデアや解決策が本当に
EDITいただければ幸いです。を私は本当に奇妙な何かに気づいた:adapter#getCount
は常にリストが空でない場合でも、0を返すため、データは、アダプタにバインドされていません。しかし、at_address.setAdapter(addressAdapter)
を削除すると、データアダプタが更新され、adapter#getCount
が正しい数の要素を返します。
私は本当に今混乱しています、助けてください!これに代えて
autoComplete()の内部は何ですか? –
リストを取得するのに使う方法ですが、うまくいきます。問題はここから来ていないと確信しています。 (もし動作していなければ 'Log.i(" addresses "、suggestions_address.toString());'何も印刷しません) –