ArrayAdapter
で利用できるタイトル/サブタイトル ビューを使用できるように、カスタムがありますListView
。文字列を受け入れてEditText
アダプターをフィルター処理する があります。
フィルターは、正しいオブジェクトをフィルタリングしているという意味で機能します (フィルターをクリックすると、正しい「エクストラ」でインテントが開始されます)。
ただし、フィルタリングが機能しても、アダプター内の項目が更新されず、正しい情報が表示されません... タイトルとサブタイトルが正しくありません。
にアイテム 0 ~ 9 があるListView
とします。検索で 3 つのアイテムにフィルターし、フィルターされたアイテムが 5、6、9 であるとします... 3 つのアイテムが表示されますが、元の pre の最初の 3 つのアイテムです。 -検索ListView
(0-2)。項目 2 (3 番目の項目) をクリックすると、新しいインテントに 9 の内容が含まれています。これは検索条件としては正しいですが、タイトルには正しい情報が反映されています。
ListView
更新するために何を伝える必要があるのか わかりません。私はそうは思わないnotifyDataSetChanged();
どんな助けでも大歓迎です。ありがとう!
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;
}
}
これが検索です
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
}
};