title: Get an activity's context from view model class
body: <p>I based my code on an example I found that uses Android Architecture Components and data binding. This is a new way for me, and the way it is coded makes it hard to properly open a new activity with the information of the post that was clicked.</p>
  
  <p>This is the adapter of the posts</p>
  
  <pre><code>class PostListAdapter : RecyclerView.Adapter&lt;PostListAdapter.ViewHolder&gt;() {
      private lateinit var posts: List&lt;Post&gt;
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PostListAdapter.ViewHolder {
          val binding: ItemPostBinding = DataBindingUtil.inflate(
              LayoutInflater.from(parent.context),
              R.layout.item_post,
              parent, false
          )
  
          return ViewHolder(binding)
      }
  
      override fun onBindViewHolder(holder: PostListAdapter.ViewHolder, position: Int) {
          holder.bind(posts[position])
      }
  
      override fun getItemCount(): Int {
          return if (::posts.isInitialized) posts.size else 0
      }
  
      fun updatePostList(posts: List&lt;Post&gt;) {
          this.posts = posts
          notifyDataSetChanged()
      }
  
      inner class ViewHolder(private val binding: ItemPostBinding) : RecyclerView.ViewHolder(binding.root) {
          private val viewModel = PostViewModel()
  
          fun bind(post: Post) {
              viewModel.bind(post)
              binding.viewModel = viewModel
          }
      }
  }
  </code></pre>
  
  <p>The <code>bind</code> method comes from within the view model class:</p>
  
  <pre><code>class PostViewModel : BaseViewModel() {
      private val image = MutableLiveData&lt;String&gt;()
      private val title = MutableLiveData&lt;String&gt;()
      private val body = MutableLiveData&lt;String&gt;()
  
      fun bind(post: Post) {
          image.value = post.image
          title.value = post.title
          body.value = post.body
      }
  
      fun getImage(): MutableLiveData&lt;String&gt; {
          return image
      }
  
      fun getTitle(): MutableLiveData&lt;String&gt; {
          return title
      }
  
      fun getBody(): MutableLiveData&lt;String&gt; {
          return body
      }
  
      fun onClickPost() {
          // Initialize new activity from here, perhaps?
      }
  }
  </code></pre>
  
  <p>And in the layout XML, setting on an <code>onClick</code> attribute</p>
  
  <blockquote>
    <p>android:onClick="@{() -> viewModel.onClickPost()}"</p>
  </blockquote>
  
  <p>pointing to this <code>onClickPost</code> method does work but I can't initialize the <code>Intent</code> from there. I tried many ways to acquire the <code>MainActivitiy</code>'s context, without success, such as</p>
  
  <blockquote>
    <p>val intent = Intent(MainActivity::getApplicationContext, PostDetailActivity::class.java)</p>
  </blockquote>
  
  <p>But it displays an error on time.</p>