javaandroidtelevision

disable onClick on recyclerView when is OnlongClick option


How to disable onClick when I click for LongClick? It's a code from recyclerView, when I try long click I just see that normal click just spamming like hell.

 holder.title.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "To clear your recomendations, press for few seconds. ", Toast.LENGTH_SHORT).show();
                    }
                });
                holder.title.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        clearPreferences(R.string.preferences_reminder);
                        Toast.makeText(context, "Recomendations cleared.", Toast.LENGTH_SHORT).show();


                        return true;
                    }
                });

Solution

  • Add this line

    holder.title.setOnClickListener(null);