0
検索フィルタが実装されている場合、誰もrecyclerviewのアイテムの位置を維持する方法を教えていただけますか?androidのrecyclerviewで検索フィルタの後に位置を維持する方法
まあシナリオでは、私は4つの位置にあるアイテムDを検索すると、アイテムDの意図アクティビティがアイテムAインテントになり、これは私が望むものではありません。
私が欲しいのは、アイテムDを検索しても、アイテムDのアクティビティは同じです。
この問題は現在2日間ストレスを与えています。だれでも助けてくれれば本当に感謝します。
は、ここに私のRecyclerViewアダプタ
public class dog_recylerAdapter extends RecyclerView.Adapter<dog_recylerAdapter.dogViewHolder> {
ArrayList<dog_counter> arrayList = new ArrayList<>();
Context dog_context;
public static int tag;
dog_recylerAdapter(ArrayList<dog_counter> arrayList, Context dog_context) {
this.arrayList = arrayList;
this.dog_context = dog_context;
}
@Override
public dogViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.petbook_dog, parent, false);
return new dogViewHolder(view, dog_context, arrayList);
}
@Override
public void onBindViewHolder(dogViewHolder holder, int position) {
holder.dog.setImageResource(arrayList.get(position).getCount());
holder.dog_name.setText(arrayList.get(position).getName());
}
@Override
public int getItemCount() {
return arrayList.size();
}
@Override
public long getItemId(int position) {
return arrayList.get(position).getCount();
}
public static class dogViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageButton dog;
TextView dog_name;
ArrayList<dog_counter> arrayList;
Context dog_context;
public dogViewHolder(View itemView, Context dog_context, ArrayList<dog_counter> arrayList) {
super(itemView);
this.arrayList = arrayList;
this.dog_context = dog_context;
itemView.setOnClickListener(this);
dog = (ImageButton) itemView.findViewById(R.id.petdog_imag1);
dog_name = (TextView) itemView.findViewById(R.id.petdog_name1);
dog.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int position = getAdapterPosition();
arrayList=new ArrayList<>();
if(position==0) {
Intent intent = new Intent(this.dog_context, dog_alaskan_malamute.class);
this.dog_context.startActivity(intent);
}
else if(position==1) {
dog.setOnClickListener(this);
Intent intent = new Intent(this.dog_context, dog_beagle.class);
this.dog_context.startActivity(intent);
}
else if(position==2) {
Intent intent = new Intent(this.dog_context, dog_chow_chow.class);
this.dog_context.startActivity(intent);
}
else if(position==3) {
Intent intent = new Intent(this.dog_context, dog_duchshand.class);
this.dog_context.startActivity(intent);
}
}
}
public void setFilter(ArrayList<dog_counter> newList) {
arrayList=new ArrayList<>();
arrayList.addAll(newList);
notifyDataSetChanged();
}
先生、これはばかげた質問かもしれませんが、私はclickedItemに何を比較するのだろうか? –
あなたの犬カウンターのモデルは何ですか?そこにIDがあると思ってください。または犬のカウンター名。ユニークなものを作る@ tyreklGana- –
ああ、ありがとうございました。 –