So, I have a custom one ArrayAdapter, so I can use the Title / Subtitle view available in ListView. I have EditTextone that takes a string and filters the adapter.
A filter works in the sense that it filters the correct objects (I can tell by clicking on it and it starts the intent with the correct "extra").
However, despite the fact that filtering works, the elements in the adapter are not updated to display the correct information ... The name and subtitles are incorrect.
Suppose we have items from 0 to 9 on ListView, I filter by 3 elements with a search, and lets say that the filtered elements are displayed 5, 6, 9 ... 3, but the first 3 elements of the initial preliminary search ListView(0-2 ) If I click on element 2 (third element), the contents of 9 will be contained in the new intent. This is true for the search criteria, however the name does reflect the correct information.
I am not sure what I need to report ListViewfor the update. I don't think himnotifyDataSetChanged();
Any help is appreciated. Thank!
public class myListAdapter extends ArrayAdapter<Pizza>{
private ArrayList<Pizza> items;
private PizzaViewHolder myListHolder;
private class PizzaViewHolder{
TextView title;
TextView subtitle;
}
public myListAdapter(Context context, int textViewResourceId, ArrayList<Pizza> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
View v = convertView;
if(v == null){
LayoutInflater vi = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.myList_item, null);
myListHolder = new PizzaViewHolder();
myListHolder.title = (TextView)v.findViewById(R.id.title);
myListHolder.subtitle = (TextView)v.findViewById(R.id.subtitle);
v.setTag(myListHolder);
}else myListHolder = (PizzaViewHolder)v.getTag();
Pizza myList = items.get(pos);
if (myList != null){
myListHolder.title.setText(myList.getTitle());
myListHolder.subtitle.setText(myList.getSubTitle());
}
return v;
}
}
This is a search
private TextWatcher filterTextWatcher = new TextWatcher(){
public void afterTextChanged(Editable s) {
if(!s.equals("")){
((Filterable) this.listView1.getAdapter()).getFilter().filter(s);
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
};