私はフィルタをかけたリストビューと、テキスト変更イベントを取得するためのTextWatcherを持っているEditTextを持っています。編集テキストからテキストを削除するまで、すべてがうまくいきます。フィルタは最初の文字のままで、フィルタには戻りません。ListViewの空のテキストフィルタ
私は間違っていますか?ここにTextWatcherのコードがありますが、私はフィルターを無効にしようとしましたが効果はありませんでした。あなたの助けの代わりにフィルタリングListView
の
私はフィルタをかけたリストビューと、テキスト変更イベントを取得するためのTextWatcherを持っているEditTextを持っています。編集テキストからテキストを削除するまで、すべてがうまくいきます。フィルタは最初の文字のままで、フィルタには戻りません。ListViewの空のテキストフィルタ
私は間違っていますか?ここにTextWatcherのコードがありますが、私はフィルターを無効にしようとしましたが効果はありませんでした。あなたの助けの代わりにフィルタリングListView
の
iはアディルSoomroの答えは悪いことだと思う...私はただ見てandroid sourceとsetFilterTextのようになります。
public void setFilterText(String filterText) {
// TODO: Should we check for acceptFilter()?
if (mTextFilterEnabled && !TextUtils.isEmpty(filterText)) {
createTextFilter(false);
// This is going to call our listener onTextChanged, but we might not
// be ready to bring up a window yet
mTextFilter.setText(filterText);
mTextFilter.setSelection(filterText.length());
if (mAdapter instanceof Filterable) {
// if mPopup is non-null, then onTextChanged will do the filtering
if (mPopup == null) {
Filter f = ((Filterable) mAdapter).getFilter();
f.filter(filterText);
}
// Set filtered to true so we will display the filter window when our main
// window is ready
mFiltered = true;
mDataSetObserver.clearSavedState();
}
}
}
あなたはそれがフィルターとアダプタの設定だ見ることができるように...
あなたはlv.clearTextFilter();
代わりに感謝
ため
EditText txtFilter = (EditText) this.findViewById(R.id.txtFilter);
txtFilter.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
if(s.length()==0)
{
lv.setTextFilterEnabled(false);
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
public void onTextChanged(CharSequence s, int start, int before, int count)
{
lv.setTextFilterEnabled(true);
lv.setFilterText(s.toString());
}
});
おかげで、この方法のようAdapter
でろ過ん:
txtFilter.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){
}
public void onTextChanged(CharSequence s, int start, int before, int count){
adapter.getFilter().filter(s);
}
});
lv.setTextFilterEnabled(false);
のを使用する必要があります!それがそれを解決しました。 –
これは問題ではありません...リストビューのsetFilterTextアダプターの下敷きのフィルターも設定 – Selvin
遅れて来た方に。 @Selvinによって提供される回答は正しいことに注意してください。 –
はい、この回答は最後よりも完全です。ご協力いただきありがとうございます。 –
+1 - あなたに同意する@Selvin。 –