title: RecyclerView: different ViewType by different button
body: <p>I have a recycler view to show an activity timeline and three floating buttons that click to add activity. How can I code three buttons to a different view? How can I pass the condition to the Adapter?</p>
  <p>Now I can show only one viewType.
  thx a lot.</p>
  <p>Adapter.java</p>
  <pre><code>public class TripAdapter extends RecyclerView.Adapter&lt;TripAdapter.TripHolder&gt; {
      private List&lt;Trip&gt; trips = new ArrayList&lt;&gt;();
      private OnItemClickListener listener;
  
      @NonNull
      @Override
      public TripHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.trip_item, parent, false);
  
          return new TripHolder(itemView);
  
      }
  
      @Override
      public void onBindViewHolder(@NonNull TripHolder holder, int position) {
          Trip currentTrip = trips.get(position);
          holder.textViewLodgingTitle.setText(currentTrip.getLodgingTitle());
          holder.textTextViewLodgingCheckInDateTime.setText(currentTrip.getLodgingCheckInDateTime());
          holder.textTextViewLodgingCheckOutDateTime.setText(currentTrip.getLodgingCheckOutDateTime());
          holder.textViewLodgingAddress.setText(currentTrip.getLodgingAddress());
  
      }
  
  
      @Override
      public int getItemCount() {
          return trips.size();
      }
  
      public void setTrips(List&lt;Trip&gt; trips) {
          this.trips = trips;
          notifyDataSetChanged();
      }
  
      public Trip getTripAt(int position) {
          return trips.get(position);
      }
  
  
       class TripHolder extends RecyclerView.ViewHolder {
          //lodging
          private TextView textViewLodgingTitle;
          private TextView textTextViewLodgingCheckInDateTime;
          private TextView textTextViewLodgingCheckOutDateTime;
          private TextView textViewLodgingAddress;
          private TextView textViewLodgingPhone;
          private TextView textViewLodgingWebsite;
          private TextView textViewLodgingEmail;
  
          public TripHolder(@NonNull View itemView) {
              super(itemView);
              context  = itemView.getContext();
              textViewLodgingTitle = itemView.findViewById(R.id.text_view_title);
              textTextViewLodgingCheckInDateTime = itemView.findViewById(R.id.text_view_start_date_time);
              textTextViewLodgingCheckOutDateTime = itemView.findViewById(R.id.text_view_end_date_time);
              textViewLodgingAddress = itemView.findViewById(R.id.text_view_description);
  
              itemView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      int position = getAdapterPosition();
                      if (listener != null &amp;&amp; position != RecyclerView.NO_POSITION) {
                          listener.onItemClick(trips.get(position));
                      }
  
                  }
              });
          }
      }
   
      public interface OnItemClickListener {
          void onItemClick(Trip trip);
      }
  
      public void setOnItemClickListener(OnItemClickListener listener) {
          this.listener = listener;
      }
  
  
  }
  </code></pre>
  <p>MainActivity.java</p>
  <pre><code>//adapter
  RecyclerView recyclerView = findViewById(R.id.recycler_view);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
          recyclerView.setHasFixedSize(true);
          final TripAdapter adapter = new TripAdapter();
        
          recyclerView.setAdapter(adapter );
          tripViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication())).get(TripViewModel.class);
          tripViewModel.getAllTrips().observe(this, new Observer&lt;List&lt;Trip&gt;&gt;() {
              @Override
              public void onChanged(@Nullable List&lt;Trip&gt; trips) {
                  adapter.setTrips(trips);
              }
          });
  
  
  
  
  //this on onActivityResult()
  else if (requestCode == ADD_LODGING &amp;&amp; resultCode == Activity.RESULT_OK) {
              //get data from lodging activity
              String lodgingTitle = data.getStringExtra(LodgingEditActivity.EXTRA_LODGING_TITLE);
              String lodgingCheckInDateTime = data.getStringExtra(LodgingEditActivity.EXTRA_LODGING_CHECK_IN_DATE_TIME);
              String lodgingCheckOutDateTime = data.getStringExtra(LodgingEditActivity.EXTRA_LODGING_CHECK_OUT_DATE_TIME);
              String lodgingDescription = data.getStringExtra(LodgingEditActivity.EXTRA_LODGING_DESCRIPTION);
              String lodgingAddress = data.getStringExtra(LodgingEditActivity.EXTRA_LODGING_ADDRESS);
              String lodgingPhone = data.getStringExtra(LodgingEditActivity.EXTRA_LODGING_PHONE);
              String lodgingWebsite = data.getStringExtra(LodgingEditActivity.EXTRA_LODGING_WEBSITE);
              String lodgingEmail = data.getStringExtra(LodgingEditActivity.EXTRA_LODGING_EMAIL);
              String lodgingImagePath = &quot;test&quot;;
  
              Trip lodging = new Trip(lodgingTitle, lodgingCheckInDateTime, lodgingCheckOutDateTime,lodgingDescription, lodgingAddress, lodgingPhone, lodgingWebsite, lodgingEmail,lodgingImagePath);
              tripViewModel.insert(lodging);
  
              Toast.makeText(this, &quot;lodging save&quot;, Toast.LENGTH_SHORT).show();
  
          }
  </code></pre>
  <p>My application I adapt from codinginflow channel.
  <a href="https://codinginflow.com/tutorials/android/room-viewmodel-livedata-recyclerview-mvvm/part-1-introduction" rel="nofollow noreferrer">https://codinginflow.com/tutorials/android/room-viewmodel-livedata-recyclerview-mvvm/part-1-introduction</a></p>