So I have a custom ArrayAdapter so I can use the Title/Subtitle view that is available on the ListView. I have an EditText that accepts a string and filters the adapter.
The filter works in the sense that it is filtering the correct objects (I can tell by clicking on it and it starts the intent with the correct "extras".)
However even though the filtering works, the items in the adapter are not updated to display the correct information... The title and subtitle are incorrect.
Lets say we have items 0 through 9 on the ListView, I filter to 3 items with a search, and lets say the filtered items are 5, 6, 9... 3 items are displayed, but its the first 3 items of the original pre-search ListView (0-2). If i click on the item 2 (the third item), the contents of 9 are contained in the new intent. This is correct for the search criteria, however the title did reflect the correct information.
I'm not sure what I need to tell the ListView to refresh.
I don't think its notifyDataSetChanged();
Any help is appreciated. Thanks!
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;
// TODO Auto-generated constructor stub
}
@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 the search
private TextWatcher filterTextWatcher = new TextWatcher(){
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if(!s.equals("")){
((Filterable) this.listView1.getAdapter()).getFilter().filter(s);
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
};