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/']
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}"/>

```
ViewModel

```
private var tapTime: Long = 0

fun onTouchListener(view:View, event: MotionEvent): Boolean {
   when (event.action) {
      MotionEvent.ACTION_DOWN -> {
          tapTime = Date().time
          // more commands for touch down event
      } 
      MotionEvent.ACTION_UP -> {
         if (Date().time - tapDate < 300) {
            view.performClick()
           // more commands if click event
         } else {
           // any commands if holded toch on screen
         } 
     }
  }
  return true
}

```

**No need for data binding adapter. It exists already.**

XML

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

```

**Warning**
You need to use the right signature in ViewModel:

```
fun name(view:View, event: MotionEvent): Boolean

```

and right name of the attribute in XML:

```
app:onTouchListener

```