Question: I'm trying to detect from my mainActivity wheter the user does a normal click or a long press because depend of it I need to do one thing or another, and I have the object of my SQLite on my MainActivity and not in my Adapter, I do not know if it's better to detect it on the Adapter or in MainActivity.

My adapter is a normal one which has a ViewHolder and items on it, but I need to detect the click on the view not on an specific view on row, can you guide me how to?

I'd like to get like a callback that detects when user does one action and depends of it do one thing or another

EXPLANATION
-----------

On my main activity I have the `private DatabaseHelper db;` object so I'd like to do something like if he does onClick view the detail onLongClick show a dialog to delete it.

Hope you understand my issue.

Answer: 
You might want to use an interface for that purpose, like such:

**Add this to your Custom Adapter:**

```
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

    private ItemClickListener mClickListener;

    public void setClickListener(ItemClickListener itemClickListener) {
        this.mClickListener = itemClickListener;
    }

    public interface ItemClickListener {
        void onItemClick(int position);

        boolean onItemLongClick(int position);
    }

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {

        ViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);
            itemView.setOnLongClickListener(this);
            itemView.setHapticFeedbackEnabled(true); // vibration feedback on long click
        }

        @Override
        public void onClick(View view) {
            if (mClickListener != null) mClickListener.onItemClick(getAdapterPosition());
        }

        @Override
        public boolean onLongClick(View view) {
            if (mClickListener != null)     mClickListener.onItemLongClick(getAdapterPosition());
            return true;
        }
    }
}

```

**And in your MainActivity implement the ItemClickListener and overwrite its methods:**

```
public class MainActivity extends AppCompatActivity
        implements MyAdapter.ItemClickListener {

    @Override
    public void onItemClick(int position) {
        //TODO Add OnClick behaviour
    }

    @Override
    public boolean onItemLongClick(int position) {
        return false;
        //TODO Add OnLongClick behaviour
    }

}

```
You have to use **Adapter** for this purpose, additionally you have to use **GestureDetector** for long press, **AlertDialog** for confirmation message and handle requisite **sqllite** accordingly.