title: Bind viewmodel to recyclerview item.xml with databinding, android?
body: <p>I want to bind data on adapter from viewmodel in xml layout file</p>
  
  <p>This is my fragment class.</p>
  
  <pre><code>class NotificationFragment : Fragment() {
  var customeProgressDialog: CustomeProgressDialog? = null
  private val appPreferences: AppPreference by inject()
  private val notificationViewModel: NotificationViewModel by viewModel()
  private lateinit var binding: FragmentNotificationBinding
  
  override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?,
      savedInstanceState: Bundle?
  ): View? {
      binding = FragmentNotificationBinding.inflate(inflater, container, false)
      return binding.getRoot()
  }
  
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
      binding.notification.layoutManager=LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
      customeProgressDialog = CustomeProgressDialog(activity)
      notificationViewModel.notifications(
          appPreferences.getUsername(),
          appPreferences.getPassword(),
          appPreferences.getUserId()
      )
      initObservables()
  }
  
  private fun initObservables() {
      notificationViewModel.progressDialog?.observe(this, Observer {
          if (it!!) customeProgressDialog?.show() else customeProgressDialog?.dismiss()
      })
      notificationViewModel.apiResponse?.observe(
          viewLifecycleOwner,
          androidx.lifecycle.Observer { response -&gt;
              if (response.dataList != null) {
                  var notificationAdapter = NotificationAdapter(response.dataList as List&lt;Data&gt;)
                  notificationAdapter.notifyDataSetChanged()
                  binding.notification.adapter = notificationAdapter
              }
          })
  }
  }
  </code></pre>
  
  <p>My viewmodel </p>
  
  <pre><code>class NotificationViewModel(networkCall: NetworkCall) : ViewModel(),
  Callback&lt;ApiResponse&gt; {
  var progressDialog: SingleLiveEvent&lt;Boolean&gt;? = null
  var apiResponse: MutableLiveData&lt;ApiResponse&gt;? = null
  var networkCall: NetworkCall;
  init {
      progressDialog = SingleLiveEvent&lt;Boolean&gt;()
      apiResponse = MutableLiveData&lt;ApiResponse&gt;()
      this.networkCall = networkCall
  }
  
  fun notifications(username: String?, password: String?, userId: String?) {
      progressDialog?.value = true
      val apiPost = ApiPost()
      apiPost.userName = username
      apiPost.password = password
      apiPost.UserId = userId
      apiPost.FileType = NetworkConstant.FILE_TYPE_NOT
      networkCall.getPDF(apiPost).enqueue(this)
  }
  
  override fun onFailure(call: Call&lt;ApiResponse&gt;, t: Throwable) {
      progressDialog?.value = false
  }
  
  override fun onResponse(call: Call&lt;ApiResponse&gt;, response: Response&lt;ApiResponse&gt;) {
      progressDialog?.value = false
      apiResponse?.value = response.body()
  }
  }
  </code></pre>
  
  <p>The adapter class</p>
  
  <pre><code>lass NotificationAdapter(private val list: List&lt;Data&gt;) :
  RecyclerView.Adapter&lt;NotificationAdapter.ViewHolder&gt;() {
  
  
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
      val inflater = LayoutInflater.from(parent.context)
      val view = inflater.inflate(R.layout.element_list, parent, false)
      return ViewHolder(view)
  }
  
  override fun onBindViewHolder(holder: ViewHolder, position: Int) {
      val movie: Data = list[position]
      holder.bind(movie)
      holder.itemView.setOnClickListener {
  
          if (!TextUtils.isEmpty(movie.filePath)) {
              try {
                  val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(movie.filePath))
                  holder.itemView.context.startActivity(browserIntent)
              } catch (e: Exception) {
                  e.printStackTrace()
              }
          }
  
      }
  }
  
  override fun getItemCount(): Int = list.size
  
  inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
      fun bind(movie: Data) {
          with(itemView) {
              tv_notifi.text = movie.displayName
              tv_date.text = movie.UpdatedDate
              if (movie.description != null) {
                  tv_brief.text = movie.description
                  tv_brief.visibility = View.VISIBLE
              }
          }
      }
  }
  
  }
  </code></pre>
  
  <p>This is my item xml layout </p>
  
  <pre><code>&lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
  &lt;data&gt;
      &lt;variable
          name="viewmodel"
          type="com.mountmeru.viewmodel.NotificationViewModel" /&gt;
  &lt;/data&gt;
  
  &lt;androidx.cardview.widget.CardView
      android:id="@+id/main_cardview"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="5dp"&gt;
  
      &lt;androidx.appcompat.widget.LinearLayoutCompat
          android:id="@+id/main_cardrl"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal"&gt;
  
          &lt;RelativeLayout
              android:id="@+id/rl_newsdate"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_weight="0.3"&gt;
  
              &lt;androidx.appcompat.widget.AppCompatTextView
                  android:id="@+id/tv_notifi"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="10dp"
                  android:layout_marginTop="10dp"
                  android:layout_marginRight="10dp"
                  android:maxLines="2"
                  android:text="hey i am notification text"
                  android:textColor="@android:color/black"
                  android:textSize="16sp" /&gt;
  
              &lt;androidx.appcompat.widget.AppCompatTextView
                  android:id="@+id/tv_brief"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/tv_notifi"
                  android:layout_marginLeft="10dp"
                  android:layout_marginTop="5dp"
                  android:layout_marginRight="10dp"
                  android:textColor="@android:color/black"
                  android:textSize="16sp"
                  android:visibility="gone" /&gt;
  
              &lt;androidx.appcompat.widget.AppCompatTextView
                  android:id="@+id/tv_date"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/tv_brief"
                  android:layout_marginLeft="10dp"
                  android:layout_marginTop="2dp"
                  android:layout_marginRight="10dp"
                  android:maxLines="1"
                  android:text="hey i am date"
                  android:textColor="@color/inactive_text"
                  android:textSize="14sp" /&gt;
          &lt;/RelativeLayout&gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_toRightOf="@+id/rl_newsdate"
              android:layout_weight="0.7"
              android:padding="5dp"&gt;
  
              &lt;androidx.appcompat.widget.AppCompatImageView
                  android:id="@+id/iv_notifi"
                  android:layout_width="match_parent"
                  android:layout_height="75dp"
                  android:layout_centerHorizontal="true"
                  android:layout_centerVertical="true"
                  android:src="@drawable/mer" /&gt;
  
          &lt;/RelativeLayout&gt;
  
      &lt;/androidx.appcompat.widget.LinearLayoutCompat&gt;
  
  &lt;/androidx.cardview.widget.CardView&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>I was able to do the binding for the fragment but for adapter I am unsure how to proceed.</p>