Я использую RecyclerView, и я создал фильтр на нем, и у меня проблема.
после того, как я нахожусь, когда нажимаю на элемент, я получаю неправильную позицию, а не один, который я искал, пожалуйста, помогите мне решить эту проблему.
Адаптер RecyclerView
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
Context context;
List<listitem_gib> getDataAdapter;
public RecyclerViewAdapter(List<listitem_gib> getDataAdapter, Context context){
super();
this.getDataAdapter = getDataAdapter;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_layout, parent, false);
ViewHolder viewHolder = new ViewHolder(v,context,getDataAdapter);
return viewHolder;
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
listitem_gib getDataAdapter1 = getDataAdapter.get(position);
holder.name.setText(getDataAdapter1.getName());
holder.num.setText(getDataAdapter1.getnum());
Picasso.with(context).load("http://i-geeky.info/android/image/" + getDataAdapter1.getimg()).into(holder.img1);
}
@Override
public int getItemCount() {
return getDataAdapter.size();
}
class ViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener{
public TextView name;
public TextView num;
public ImageView img1;
ImageButton fav;
Context context;
List<listitem_gib> getDataAdapter;
public ViewHolder(View itemView, Context context ,List<listitem_gib> getDataAdapter ) {
super(itemView);
itemView.setOnClickListener(this);
this.getDataAdapter = getDataAdapter;
this.context = context;
this.fav= (ImageButton) itemView.findViewById(R.id.btn_fav);
name = (TextView) itemView.findViewById(R.id.Main_Text) ;
num = (TextView) itemView.findViewById(R.id.Second_Text) ;
img1 = (ImageView) itemView.findViewById(R.id.img1) ;
}
@Override
public void onClick(View v) {
int position = getAdapterPosition();
listitem_gib getDataAdapter =this.getDataAdapter.get(position);
Intent intent = new Intent(this.context,Rewaya_info.class);
intent.putExtra("name",getDataAdapter.getName());
intent.putExtra("url",getDataAdapter.geturl());
intent.putExtra("img",getDataAdapter.getimg());
intent.putExtra("num",getDataAdapter.getnum());
intent.putExtra("size",getDataAdapter.getsize());
this.context.startActivity(intent);
}
}
public void setFilter(List<listitem_gib> newList)
{
getDataAdapter = new ArrayList<>();
getDataAdapter.addAll(newList );
notifyDataSetChanged();
}}
Деятельность
@Override
public boolean onQueryTextChange(String newText) {
newText = newText.toLowerCase();
List<listitem_gib> newList = new ArrayList<>();
for (listitem_gib list : GetDataAdapter1){
String name = list.getName().toLowerCase();
String name1 = list.getnum().toLowerCase();
if (name.contains(newText) || name1.contains(newText)){
newList.add(list);
}
}
recyclerViewadapter.setFilter(newList);
return true;
}