Мне нужно реализовать функцию поиска на основе EditText для моего RecyclerView, список должен быть отфильтрован, а typng
Здесь код:
DisplayAdapter.java это адаптер
public class DisplayAdapter extends RecyclerView.Adapter<DisplayAdapter.MyViewHolder>{
private List<DataHolder> displayedList;
public class MyViewHolder extends RecyclerView.ViewHolder{
public TextView english_d;
public MyViewHolder(View view){
super(view);
english_d = (TextView) view.findViewById(R.id.engword);
}
}
public DisplayAdapter(List<DataHolder> displayedList){
this.displayedList = displayedList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int position) {
// create a layout
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
DataHolder content = displayedList.get(position);
holder.english_d.setText(content.getEnglish());
}
@Override
public int getItemCount() {
return displayedList.size();
}
}
DataHolder.java
public class DataHolder {
private String english;
public DataHolder() {
}
public DataHolder(String english, String norse) {
this.english = english;
}
public String getEnglish() {
return english;
}
public void setEnglish(String english) {
this.english = english;
}
}
и здесь Фрагмент, с которым я работаю:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_two_fragment, container, false);
rv = (RecyclerView) view.findViewById(R.id.list_view_english);
rv.setHasFixedSize(true);
inputSearch = (EditText) view.findViewById(R.id.inputSearch);
rv.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL));
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
rv.setLayoutManager(layoutManager);
DisplayContent();
disp_adapter = new DisplayAdapter(displayedList);
rv.setAdapter(disp_adapter);
return view;
}