title: Databinding Recyclerview and onClick
body: <p>Ok I'll try one more time. Last time I asked about passing data between recyclerview and item and one person helped me with open item by click, but I still don't have idea how to show the data of clicked item in new activity. I want to click on an item and then display the data of that item in new activity. In this activity I want to edit data.
  Does anyone knows how to do it? I need any idea.</p>
  
  <p>RecyclerView Adapter with OnItemClickListener interface:</p>
  
  <pre><code>public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.TaskViewHolder&gt; {
  
  private List&lt;MainViewModel&gt; mTasks;
  private List&lt;Task&gt; tasks = new ArrayList&lt;&gt;();
  private Context context;
  private EditTaskViewModel editTaskViewModel;
  
  
  public RecyclerViewAdapter(List&lt;MainViewModel&gt; tasks, Context context, EditTaskViewModel editTaskViewModel) {
      this.mTasks = tasks;
      this.context = context;
      this.editTaskViewModel = editTaskViewModel;
  }
  
  
  @NonNull
  @Override
  public RecyclerViewAdapter.TaskViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      LayoutInflater inflater = LayoutInflater.from(parent.getContext());
      final RecyclerViewItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.recycler_view_item, parent, false);
  
      binding.setItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(View view) {
              Intent intent = new Intent(view.getContext(), EditTaskActivity.class);
              intent.putExtra("id", binding.getPosition());
              view.getContext().startActivity(intent);
              Toast.makeText(view.getContext(), "ID " + binding.getPosition(), Toast.LENGTH_SHORT).show();
  
          }
      });
      return new TaskViewHolder(binding);
  }
  
  @Override
  public void onBindViewHolder(@NonNull final RecyclerViewAdapter.TaskViewHolder holder, final int position) {
      Task currentTask = tasks.get(position);
      holder.mBinding.descriptionItem.setText(currentTask.getDescription());
      holder.mBinding.dateItem.setText(currentTask.getDate());
      holder.mBinding.timeItem.setText(currentTask.getTime());
      holder.mBinding.setPosition(position);
  }
  
  @Override
  public int getItemCount() {
      return tasks.size();
  }
  
  public void setTasks(List&lt;Task&gt; tasks) {
      this.tasks = tasks;
      notifyDataSetChanged();
  }
  
  public Task getTaskPosition(int position) {
      return tasks.get(position);
  }
  
  public class TaskViewHolder extends RecyclerView.ViewHolder {
      private final RecyclerViewItemBinding mBinding;
  
      public TaskViewHolder(RecyclerViewItemBinding binding) {
          super(binding.getRoot());
          this.mBinding = binding;
      }
  
          public void bind (MainViewModel mainViewModel){
              mBinding.setItemView(mainViewModel);
              mBinding.executePendingBindings();
          }
      }
  
      public interface OnItemClickListener {
          void onItemClick(View view);
      }
  </code></pre>
  
  <p>Item XML file:</p>
  
  <pre><code>&lt;layout xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  &lt;data&gt;
      &lt;variable
          name="itemView"
          type="com.example.daniellachacz.taskmvvm.viewmodel.MainViewModel"&gt;
      &lt;/variable&gt;
  
      &lt;variable
          name="itemClickListener"
          type="com.example.daniellachacz.taskmvvm.adapter.RecyclerViewAdapter.OnItemClickListener"&gt;
      &lt;/variable&gt;
  
      &lt;variable
          name="task"
          type="com.example.daniellachacz.taskmvvm.model.Task"&gt;
      &lt;/variable&gt;
  
      &lt;variable
          name="position"
          type="int"&gt;
      &lt;/variable&gt;
  
  &lt;/data&gt;
  
  &lt;android.support.v7.widget.CardView
  android:layout_width="match_parent"
  android:layout_height="120dp"
  android:shadowColor="@color/colorPrimary"
  android:backgroundTint="@color/cardview_shadow_end_color"&gt;
  
  &lt;RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="110dp"
  android:layout_marginBottom="6dp"
  android:layout_marginTop="6dp"
  android:layout_marginStart="6dp"
  android:layout_marginEnd="6dp"
  android:onClick="@{(view)-&gt; itemClickListener.onItemClick(view)}"&gt;
  
  &lt;TextView
      android:id="@+id/description_item"
      android:layout_width="250dp"
      android:layout_height="96dp"
      android:layout_marginStart="5dp"
      android:layout_marginTop="9dp"
      android:layout_marginBottom="5dp"
      android:text="@{itemView.description}"
      android:textSize="18sp"
      android:textColor="#020202"
      android:focusable="true" /&gt;
  
  &lt;TextView
      android:id="@+id/date_item"
      android:layout_width="90dp"
      android:layout_height="40dp"
      android:layout_alignParentTop="true"
      android:layout_alignParentEnd="true"
      android:layout_marginTop="9dp"
      android:layout_marginEnd="10dp"
      android:gravity="center"
      android:text="@{itemView.date}"
      android:textColor="#020202"
      android:textSize="16sp" /&gt;
  
  &lt;TextView
      android:id="@+id/time_item"
      android:layout_width="90dp"
      android:layout_height="40dp"
      android:layout_alignParentBottom="true"
      android:layout_alignStart="@+id/date_item"
      android:layout_marginBottom="10dp"
      android:layout_marginEnd="10dp"
      android:gravity="center"
      android:text="@{itemView.time}"
      android:textColor="#020202"
      android:textSize="16sp" /&gt;
  
      &lt;/RelativeLayout&gt;
      &lt;/android.support.v7.widget.CardView&gt;
  
      &lt;/layout&gt;
  </code></pre>
  
  <p>onCreate:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  floatingActionButton = findViewById(R.id.floating_action_button);
  
  List&lt;Task&gt; tasks = new ArrayList&lt;&gt;();
  
  RecyclerView recyclerView = findViewById(R.id.recycler_view);
  recyclerView.setLayoutManager(new LinearLayoutManager(this));
  recyclerView.setHasFixedSize(true);
  
  final RecyclerViewAdapter recyclerViewAdapter = new     RecyclerViewAdapter(context, tasks);
  recyclerView.setAdapter(recyclerViewAdapter);
  
  mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
  mainViewModel.getAllTasks().observe(this, recyclerViewAdapter::setTasks);
  </code></pre>