Using RecyclerView I display two texts in one item, but after filtering, they are displayed asynchronously.
The reason after filtering is to create a new ArrayList , which is filled with data that matches the ones I conducted in the search. Thus, the first field is filled, and the second is filled in by position, respectively, the position after entering changes and the second field does not coincide with the first one.
Adaptar
public class CheeseAdapter extends RecyclerView.Adapter<CheeseAdapter.Holder> { private final LayoutInflater mInflater; private List<String> mDefaultCheeses; private List<String> mDefaultCheeses2; private List<String> mFilteredCheeses; private List<String> mFilteredCheeses2; List<Integer> arrImage; public CheeseAdapter(LayoutInflater inflater, String[] titleTab, String[] prichTab, List<Integer> arrImage) { mInflater = inflater; // получаю массив для первого пункта mDefaultCheeses = Arrays.asList(titleTab); mFilteredCheeses = mDefaultCheeses; // для второго mDefaultCheeses2 = Arrays.asList(prichTab); mFilteredCheeses2 = mDefaultCheeses2; // картинку this.arrImage=arrImage; } @Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) { return new Holder(mInflater.inflate(R.layout.item_layout, parent, false)); } @Override public void onBindViewHolder(Holder holder, int position) { View itemView = holder.itemView; TextView title = (TextView) itemView.findViewById(R.id.cheeseName); TextView title2 = (TextView) itemView.findViewById(R.id.person_age); ImageView personPhoto = (ImageView) itemView.findViewById(R.id.person_photo); // вставляем в первый TextView title.setText(mFilteredCheeses.get(position)); // второй title2.setText(mFilteredCheeses2.get(position)); // картинка personPhoto.setImageResource(arrImage.get(position)); } @Override public int getItemCount() { return mFilteredCheeses.size(); } public void filter(String query) { mFilteredCheeses = new ArrayList<>(); // находит совпадения for (String cheese : mDefaultCheeses) { if(cheese.toLowerCase().contains(query.toLowerCase())) { // добавляет в ArrayList mFilteredCheeses.add(cheese); } } // обновляется список notifyDataSetChanged(); } public class Holder extends RecyclerView.ViewHolder { public Holder(View itemView) { super(itemView); } } } 