Question: ```
   recyclerView.addOnItemTouchListener(new GalleryAdapter.RecyclerTouchListener(this, recyclerView, new GalleryAdapter.ClickListener()
        {

            @Override
            public void onClick(View view, int position) {
                //Values are passing to activity & to fragment as well

                int id = view.getId();

                    if(id == R.id.carasoul_button) {
                        Intent intent = new Intent(mainActivityCarasoul.this, PDFViewerActivity.class);
                        intent.putExtra(PDFViewerActivity.TAG, books.get(position));
                        intent.putExtra("from", "mo2lfatActivity");
                        startActivity(intent);
                    }

            }

            @Override
            public void onLongClick(View view, int position) {

            }
        }));

```

what this code does is when i click on the item in recycle view another activity will be opened, i wanna change that with a button that can be pressed that will open the activity.

I tried the above code and it didn't work. i put the button outside the RecycleView 

The button is not in this xml layout.gallery\_thumbnail.If i put it here it will be in all the views. The button is in the main xml which has recycle view itself. 

```
@Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.gallery_thumbnail, parent, false);

        return new MyViewHolder(itemView);
    }

```

Answer: 
If you want to position of your item then just add a tag of that view in your `onBindViewHolder` method. Here is the code example:

```
@Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
     holder.yourButton.setTag(position);
}

```

In your ViewHolder Constructor method, add onClickListener on your button.
here is sample:

```
    public MyViewHolder(View view) {
                    super(view);
        Button yourButton = (Button) view.findViewById(R.id.YOUR_BUTTON_ID);

        yourButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

  Button button = (Button) v.findViewById(R.id.YOUR_BUTTON_ID);
        Intent intent = new Intent(context, PDFViewerActivity.class);
                intent.putExtra(PDFViewerActivity.TAG, ""+button.getTag());
                intent.putExtra("from","mo2lfatActivity");
                context.startActivity(intent);
        }
    }

```

Here, context is the activity context, that can you pass by Adapter Constructor.

Thanks :)
In your `ViewHolder` class you can set `OnClickListener` for that button and override `onClick()` method to open another activity.

```
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public Button btMyButton;

    public ViewHolder(View itemView) {
        super(itemView);
        btMyButton = (Button) itemView.findViewById(R.id.bt_my_button);
        btMyButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.bt_my_button){
           Intent intent = new Intent(v.getContext(), PDFViewerActivity.class);
           intent.putExtra(PDFViewerActivity.TAG, books.get(getAdapterPosition()));
           intent.putExtra("from","mo2lfatActivity");
           startActivity(intent);               
        }
    }
 }

```