我想通過RecyclerView
搜索,我有List<BaseOfCards>
(BaseOfCards是我的getter &二傳手類) 我RecyclerViewAdapter:搜索通過RecyclerView使用搜索查看
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {
private LayoutInflater inflater;
private List<BaseOfCards> items;
//private int itemLayout;
//String cardvalue;
private Activity mActivity;
public RecyclerViewAdapter(Activity mActivity, Context context, List<BaseOfCards> items) {
this.mActivity = mActivity;
inflater = LayoutInflater.from(context);
this.items = items;
//this.itemLayout = itemLayout;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.custom_row, parent, false);
MyViewHolder holder = new MyViewHolder(view, mActivity);
return holder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
BaseOfCards item = items.get(position);
holder.title.setTag(item);
holder.title.setText(item.getCardName());
}
@Override
public int getItemCount() {
return items.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
private Activity mActivity;
TextView title;
ImageView titileImageView;
public MyViewHolder(View itemView, Activity mActivity) {
super(itemView);
titileImageView = (ImageView) itemView.findViewById(R.id.image_country);
title = (TextView) itemView.findViewById(R.id.listText);
this.mActivity = mActivity;
}
}
}
我添加搜索查看我的菜單,並在初始化MainActivity:
MenuItem menuItem = menu.findItem(R.id.action_search1);
searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setIconifiedByDefault(true);
我需要什麼,下一步該怎麼做?讓我的RecyclerViewAdapterimplement Filterable
還是什麼?或者只是在* RecyclerViewAdapter **中創建類filter
,並從我的MainActivity中調用它?
很酷,我會在我的https://github.com/davideas/FlexibleAdapter ;-)中加入這個功能('getFilter');-) – Davidea 2015-07-20 21:03:04
@Davidea哦,非常棒,非常感謝! – Ololoking 2015-07-20 21:59:33
我添加了這個功能,但它比預想的更復雜。事實上,我不相信在適配器中有這樣的過濾器,因爲適配器中的對象已經是**原始內容中來自諸如DB/XML/JSON之類的源的副本,作爲域對象 - 問題不在過濾器上,而是在**過濾的**列表上執行的add/del/mod:所有更改都應該反映在「原始」適配器列表中** AND **在原始源代碼中... At此點更方便直接從源和更新適配器與該列表中篩選複製列表。 – Davidea 2015-07-21 11:56:58