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

```
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

```