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 :)
**First, add implementation to your activity:**

```
public class Main extends ActionBarActivity implements View.OnClickListener {
   // do your stuff
}

```

This:

```
buttonname.setOnClickListener(this);

```

means that you want to assign listener for your Button "on this instance" -> this instance represents OnClickListener and for this reason your class have to implement that interface.

It's similar with anonymous listener class (that you can also use):

```
buttonname.setOnClickListener(new View.OnClickListener() {

   public void onClick(View view) {
        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
            // Toast.makeText(mainActivityCarasoul.this, "Single Click on position: "+position,
            // Toast.LENGTH_SHORT).show();
            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) {

        }
    }));
   }
});

```