我有一个ListView
并且我正在覆盖getView
使用以下代码正确填充的方法。如果我使用'adapter.getfilter()',它不会更新列表视图,尽管在适配器中它被过滤并在NEXT过滤器完成时由'out()'正确显示,在编辑框中输入文本。知道如何在我同时覆盖getView
和过滤影响适配器而不是下一次在编辑框中输入文本时启用过滤吗?
final ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
android.R.layout.activity_list_item,stringArray)
{ @Override
public View getView(int position, View convertView, ViewGroup parent)
{View row= super.getView(position, convertView, parent);
View row=convertView;
if(position==0){
row = mLayoutInflater.inflate(R.layout.list_header, null);
final TextView sectionView = (TextView) row.findViewById(R.id.list_item_section_text);
sectionView.setText(myList.get(position));
}
else
{row = mLayoutInflater.inflate(R.layout.list_item, null);
final TextView sectionView = (TextView) row.findViewById(R.id.list_item_entry_title);
sectionView.setText(myList.get(position));}
return row;}});
lv.setAdapter(adapter);
for (int i = 0; i < adapter.getCount(); i++) {//displaying properly
pr("adapter list"+adapter.getItem(i));
}
myFilter.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);
adapter.notifyDataSetChanged();
for (int i = 0; i < adapter.getCount(); i++) {
pr("adapter list before "+ (adapter.getItem(i)));//printing properly but not
//updated in listview ,sometimes it just displays first few ,even if it should not be
//in filtered result after filtering.
} } });