title: Show empty view when data set is empty in recyclerview
body: <p>I have a recyclerview which shows multiple cardviews with items. In the recyclerview, I have a popup menu to delete that current cardview. </p>
  
  <p>When the dataset is empty I would like to show an empty view. Something with an image and text saying "empty" I have tried some online examples. No success.</p>
  
  <p>My layout is a cardview(<strong>card_view_row.xml</strong>) is a simple view with a cardview that shows a few items.</p>
  
  <p>Here is my recyclerview</p>
  
  <pre><code>public class AlarmRecyclerViewAdapter extends 
   RecyclerView.Adapter&lt;AlarmRecyclerViewAdapter.DataObjectHolder&gt; {
  
      private ArrayList&lt;Alarm&gt; mDataset;
      private static AlarmRecyclerViewAdapter.MyClickListener myClickListener;
      private AlarmDataAccess dataAccess;
  
      private Alarm alarm;
      private int switchOn = 1;
      private int switchOff = 0;
      private static Context context;
      private PopupMenu popupMenu;
  
  
      public static class DataObjectHolder extends RecyclerView.ViewHolder
              implements View
              .OnClickListener {
          TextView label;
          TextView dateTime;
          TextView label2;
          TextView textViewLabel;
          TextView gender;
          TextView daysofweek;
          Switch aSwitch;
          ImageView trash;
  
  
          public DataObjectHolder(View itemView) {
              super(itemView);
  
              dateTime = (TextView) itemView.findViewById(R.id.textView2);
              label = (TextView) itemView.findViewById(R.id.textView);
              label2 =(TextView) itemView.findViewById(R.id.textView3);
              aSwitch = (Switch)itemView.findViewById(R.id.switchButton);
              trash = (ImageView)itemView.findViewById(R.id.imageTrash);
              gender = (TextView)itemView.findViewById(R.id.textViewGender);
              daysofweek = (TextView)itemView.findViewById(R.id.textViewDays);
              textViewLabel = (TextView)itemView.findViewById(R.id.textViewLabel);
  
              itemView.setOnClickListener(this);
          }
  
          @Override
          public void onClick(View v) {
              myClickListener.onItemClick(getAdapterPosition(), v);
          }
      }
  
      public void setOnItemClickListener(AlarmRecyclerViewAdapter.MyClickListener myClickListener) {
          this.myClickListener = myClickListener;
      }
  
      public AlarmRecyclerViewAdapter(ArrayList&lt;Alarm&gt; myDataset, Context context2) {
          mDataset = myDataset;
          context = context2;
      }
  
      @Override
      public AlarmRecyclerViewAdapter.DataObjectHolder onCreateViewHolder(ViewGroup parent,
                                                                          int viewType) {
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_row, parent, false);
          AlarmRecyclerViewAdapter.DataObjectHolder dataObjectHolder = new AlarmRecyclerViewAdapter.DataObjectHolder(view);
          return dataObjectHolder;
      }
  
      @Override
      public void onBindViewHolder(final AlarmRecyclerViewAdapter.DataObjectHolder holder, final int position) {
          boolean status = false;
          int gender;
  
          alarm = new Alarm();
  
          dataAccess = new AlarmDataAccess(context);
          dataAccess.open();
  
          holder.label.setText(mDataset.get(position).getHourOfDay() + ":" + mDataset.get(position).getMinute() + " " + mDataset.get(position).getTimeSet());
          holder.textViewLabel.setText(mDataset.get(position).getLabel());
  
          gender = mDataset.get(position).getGender();
          if(gender == 0){
              holder.gender.setText("Male voice");
          }else{
              holder.gender.setText("Female voice");
          }
  
          holder.daysofweek.setText(mDataset.get(position).getDays());
          holder.label2.setText("" + mDataset.get(position).getAffirmationName());
  
  
          holder.trash.setImageResource(R.drawable.menu2);
  
  
          if( mDataset.get(position).getStatus() == 0){
              status = false;
          }else {
              status = true;
          }
  
          holder.aSwitch.setChecked(status);
  
  
          holder.aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  
                  if (buttonView.isPressed()) {
                      if (isChecked) {
                          mDataset.get(position).setStatus(switchOn);
                      } else {
                          mDataset.get(position).setStatus(switchOff);
                      }
                      alarm.setId(mDataset.get(position).getId());
                      alarm.setStatus(mDataset.get(position).getStatus());
                      dataAccess.updateStatus(alarm);
                  }
              }
  
          });
  
  
          holder.trash.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  popupMenu = new PopupMenu(AlarmRecyclerViewAdapter.context, v);
                  popupMenu.inflate(R.menu.popup_menu);
                  popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                      @Override
                      public boolean onMenuItemClick(MenuItem item) {
                          switch (item.getItemId()) {
                              case R.id.edit:
                                  long selectedAlarmId = mDataset.get(position).getId();
                                  Intent intent = new Intent(AlarmRecyclerViewAdapter.context, EditAlarmActivity.class);
                                  intent.putExtra("id", selectedAlarmId);
                                  intent.putExtra("Edit", "FromEdit");
                                  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
                                  AlarmRecyclerViewAdapter.context.startActivity(intent);
                                  return true;
                              case R.id.delete:
                                  long id = mDataset.get(position).getId();
                                  mDataset.remove(position);
                                  notifyItemRemoved(position);
                                  notifyItemRangeChanged(position, mDataset.size());
                                  dataAccess.deleteAlarm(id);
                                  return true;
                          }
                          return false;
  
                      }
                  });
  
                  popupMenu.show();
              }
          });
      }
  
      public void deleteItem(int index) {
          mDataset.remove(index);
          notifyItemRemoved(index);
      }
  
      @Override
      public int getItemCount() {
          return mDataset.size();
      }
  }
  </code></pre>
  
  <p>My recyclerview is inside a fragment view</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@+id/fragment_place"&gt;
  
      &lt;ImageButton
          android:id="@+id/add_button"
          android:layout_width="48dp"
          android:layout_height="48dp"
          android:layout_gravity="end|bottom"
          android:tint="@color/icon"
          android:elevation="12dp"
          android:background="@drawable/oval_ripple"
          tools:backgroundTint="#96ceb4"
          android:src="@android:drawable/ic_input_add"
          android:layout_alignParentTop="true"
          android:layout_alignParentStart="true"
          android:layout_marginStart="12dp"
          android:layout_marginTop="14dp" /&gt;
  
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/my_recycler_view"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:scrollbars="vertical"
          android:layout_below="@+id/add_button"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="16dp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Is there a way to detect if the data set is empty to show an empty view with text saying empty or something? I need this done inside recyclerview since I am deleting items inside there.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I finally figured out how to do it. I am posting this incase anyone else has the same problem.</p>
  
  <pre><code>http://akbaribrahim.com/empty-view-for-androids-recyclerview/
  </code></pre>