luizgrp / SectionedRecyclerViewAdapter

An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
MIT License
1.68k stars 372 forks source link

Clicking twice for items #21

Closed KarimFikani closed 7 years ago

KarimFikani commented 7 years ago

I'm not sure if anyone has faced this issue before but the problem that I'm facing is the following: I have a menu fragment that slides in from the left when a menu buttons is tapped. Inside that menu fragment I have a recyclerview and I feed it as an adapter SectionRecyclerViewAdapter. Everything works fine but when I scroll to see the not visible items and click on one of the new items, I end up clicking twice to select it. I can reproduce 100% of the time. I realized that it was always the items that become visible are the ones that I have to click twice and it might be related to the adapter.

Here is what I'm doing in my viewholder:

@Override    
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        final MenuExtrasViewHolder itemHolder = (MenuExtrasViewHolder) holder;

        final MenuExtra extra = extras.getExtra(position);
        itemHolder.setRelativePosition(position);

        setImage(extra, itemHolder);
        setTitle(extra, itemHolder);

        itemHolder.getRootView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "onClick");
                final MenuExtra extra = extras.getExtra(itemHolder.getRelativePosition());

                if (extra.isRateApp()) {
                    rateApp();

                } else if (extra.isShareApp()) {
                    shareApp();
                }

                Analytics.get().logExtras(extra.getTitle());
            }
        });
    }

The log would only show onClick once when the second tap happens. How can I solve this as it is very annoying.

yccheok commented 7 years ago

@KarimFikani I didn't notice this problem by using current lib. Do you still face the same problem?

KarimFikani commented 7 years ago

Sorry for the late reply but yes I still do face the same problem.

luizgrp commented 7 years ago

Could you please paste the code of your MenuExtrasViewHolder ?

KarimFikani commented 7 years ago
class MenuExtrasViewHolder extends MenuItemViewHolder {

    public MenuExtrasViewHolder(View view) {
        super(view);
    }
}