title: Add item to RecyclerView from AlertDialog input
body: <p>I'm currently having trouble with adding a second+ items to a <code>RecyclerView</code> after inputting data in an alertdialog box.</p>
  <p>I can enter 1 set of data but when I try to add more, it doesn't do anything.</p>
  <p>This is my Java file for the fragment i'm working with:</p>
  <pre><code>public class tab1Expenses extends Fragment  {
      List&lt;ExRow&gt; expenseList = new ArrayList();
      RecyclerView recyclerView;
      ExpensesAdapter mAdapter;
      Button btnEx;
      EditText txtExName;
      EditText txtExAmount;
  
      public void expenseData() {
          String Na = txtExName.getText().toString();
          String Am = txtExAmount.getText().toString();
  
          ExRow exs = new ExRow(Na, Am);
          expenseList.add(exs);
  
          mAdapter.notifyDataSetChanged();
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
          final View rootView = inflater.inflate(R.layout.tab1expense, container, false);
          btnEx = (Button) rootView.findViewById(R.id.btnEx);
          recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
  
          mAdapter = new ExpensesAdapter(expenseList);
          final RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
          recyclerView.setLayoutManager(mLayoutManager);
          recyclerView.setItemAnimator(new DefaultItemAnimator());
          recyclerView.setAdapter(mAdapter);
   
          btnEx.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  View view = LayoutInflater.from(tab1Expenses.this.getActivity())
                      .inflate(R.layout.add_ex, null);
                  txtExName = (EditText) view.findViewById(R.id.exName);
                  txtExAmount = (EditText) view.findViewById(R.id.exAmount);
  
                  AlertDialog.Builder add = new AlertDialog.Builder(tab1Expenses.this.getActivity());
                  add.setCancelable(true)
                      .setTitle(&quot;Enter Expense:&quot;)
                      .setView(view)
                      .setPositiveButton(&quot;Add&quot;, new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              expenseData();
                          }
                     });
                  Dialog dialog = add.create();
                  dialog.show();
              }
          });
  
          return rootView;
      }
  }
  </code></pre>
  <p>And the Java file for the adapter:</p>
  <pre><code>public class ExpensesAdapter extends RecyclerView.Adapter&lt;ExpensesAdapter.MyViewHolder&gt; {
      private List&lt;ExRow&gt; expenseList;
  
      public class MyViewHolder extends RecyclerView.ViewHolder {
          public TextView title, amount;
  
          public MyViewHolder(View view) {
              super(view);
              title = (TextView) view.findViewById(R.id.name);
              amount = (TextView) view.findViewById(R.id.amount);
          }
      }
  
      public ExpensesAdapter(List&lt;ExRow&gt; expenseList) {
          this.expenseList = expenseList;
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.expense_list, parent, false);
  
          return new MyViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(MyViewHolder holder, int position) {
          ExRow expense = expenseList.get(position);
          holder.title.setText(expense.getTitle());
          holder.amount.setText(expense.getAmount());
      }
  
      @Override
      public int getItemCount() {
          return expenseList.size();
      }
  }
  </code></pre>
  <p>The XML to format the recyclerview list items:</p>
  <pre><code>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  android:orientation=&quot;vertical&quot; android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;&gt;
  
  &lt;TextView
      android:id=&quot;@+id/name&quot;
      android:textColor=&quot;@color/title&quot;
      android:textSize=&quot;16dp&quot;
      android:textStyle=&quot;bold&quot;
      android:layout_alignParentLeft=&quot;true&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot; /&gt;
  
  &lt;TextView
      android:id=&quot;@+id/amount&quot;
      android:textColor=&quot;#000000&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_alignParentRight=&quot;true&quot;
      android:layout_height=&quot;wrap_content&quot; /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  <p>And this is the XML for the fragment:</p>
  <pre><code>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  android:paddingBottom=&quot;@dimen/activity_vertical_margin&quot;
  android:paddingLeft=&quot;@dimen/activity_horizontal_margin&quot;
  android:paddingRight=&quot;@dimen/activity_horizontal_margin&quot;
  android:paddingTop=&quot;@dimen/activity_vertical_margin&quot;
  tools:context=&quot;com.example.ojemz.expensetracker.tab1Expenses&quot;
  android:background=&quot;@android:color/darker_gray&quot;&gt;
  
  &lt;Button
      android:text=&quot;Add Expense&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:id=&quot;@+id/btnEx&quot;
      android:layout_alignParentBottom=&quot;true&quot;
      android:layout_centerHorizontal=&quot;true&quot;
      android:width=&quot;800dp&quot;
      android:textAppearance=&quot;@style/TextAppearance.AppCompat.Widget.Switch&quot;
      android:background=&quot;@android:color/black&quot;
      android:textColor=&quot;@android:color/holo_green_light&quot;
      android:textColorLink=&quot;@android:color/holo_green_light&quot; /&gt;
  
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:orientation=&quot;vertical&quot; &gt;
  
  
            &lt;android.support.v4.widget.NestedScrollView
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;450dp&quot;
              android:layout_alignParentBottom=&quot;true&quot;
              android:layout_alignParentStart=&quot;true&quot;
              android:layout_marginBottom=&quot;17dp&quot;&gt;
  
          &lt;android.support.v7.widget.RecyclerView
              android:id=&quot;@+id/recycler_view&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;450dp&quot;
              android:scrollbars=&quot;vertical&quot;
              android:keepScreenOn=&quot;true&quot;
              android:isScrollContainer=&quot;true&quot; /&gt;
              
          &lt;/android.support.v4.widget.NestedScrollView&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/rCm1t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rCm1t.png" alt="This is how im inputting information" /></a>
  <a href="https://i.stack.imgur.com/7Fe7b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7Fe7b.png" alt="This is what I currently see AFTER adding a 2nd input" /></a></p>
  <p>This is what I currently see AFTER adding a 2nd input</p>