I am using recyclerview in my app. I want to start a fragment when click on image view. But i don't know how to. Also i want to put data when starting fragment. I know how to start the activity with below code. But how can i start fragment same way?

Edited Code

```
   FragmentManager fm = getSupportFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   ft.replace(R.id.layoutContent, frag);
   ft.commit();

```
['https://Stackoverflow.com/questions/45692532', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8042837/']
Here is a workaround which you can use to do this.

```
@BindingAdapter("touchListener")
public void setTouchListener(View self,boolean value){
    self.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // Check if the button is PRESSED
            if (event.getAction() == MotionEvent.ACTION_DOWN){
                //do some thing
            }// Check if the button is RELEASED
            else if (event.getAction() == MotionEvent.ACTION_UP) {
                //do some thing
            }
            return false;
        }
    });
}

```

And then in xml 

```
<Button  app:touchListener="@{true}"/>

```
ViewModel

```
public class RecyclerViewModel   {
      public View.OnTouchListener onTouchListener;

      public void setOnTouchListener( View.OnTouchListener onTouchListener) {
          this.onTouchListener = onTouchListener;
      }
}

```

DataBinding

```
@BindingAdapter("onTouchListener")
public static void setOnTouchListener(View view, View.OnTouchListener onTouchListener) {
    if (onTouchListener != null)
        view.setOnTouchListener(onTouchListener);
}

```

Use in xml

```
<Button app:onTouchListener="@{viewModel.onTouchListener}"/>

```