Skip to content Skip to sidebar Skip to footer

Recyclerview Item Onclick Not Working While Being Updated Rapidly

I bet it's a trivial mistake. But here I sit, wasting hours on it: I have a simple app that scans for Bluetooth devices and shows the discovered devices' information in cards in a

Solution 1:

Instead you can place the setOnClickListener inside your class that extends RecyclerView.ViewHolder.

classMyViewHolderextendsRecyclerView.ViewHolder {
        TextView txtDate;
        TextView txtDescription;


        MyViewHolder (View itemView) {
            super(itemView);
           //...findViewById
            itemView.setOnClickListener(newView.OnClickListener() {
                @OverridepublicvoidonClick(View view) {
                    intposition= getAdapterPosition();
                   //Do something here...
                }
            });
        }

So your onCreateViewHolder(...) method becomes:

@Overridepublic MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Viewview= inflater.inflate(R.layout.my_layout, parent, false);
        returnnewMyViewHolder(view);
    }

Post a Comment for "Recyclerview Item Onclick Not Working While Being Updated Rapidly"