title: How can I insert element in Recycler View?
body: <p>I have a problem with RecyclerView.
  Every time I try to manage a Rec View for insert or delete or update some element I have to fight with Recycler View and the evil notifyDataSetChange.</p>
  
  <p>I tried with runOnUiThread and everytime this solution is useless.
  I tried to call notifyDataSetChange in the Adapter or in the Activity that instance the Rec View.</p>
  
  <p>I really need to know how to make this work everytime to be a little better developer.
  I really hope to solve this problem definitely.</p>
  
  <p>This is my new try</p>
  
  <pre><code>
  public class MainActivity extends AppCompatActivity {
  
  
      private Button nextTurn;
      private Button submit;
      private EditText name;
      private EditText number;
  
      private CounterElementAdapter mAdapter;
      private RecyclerView recV;
      private List&lt;CounterElement&gt; list;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          nextTurn = (Button) findViewById(R.id.button2);
          submit = (Button) findViewById(R.id.button);
          name = (EditText) findViewById(R.id.editText);
          number = (EditText) findViewById(R.id.editText2);
          recV = (RecyclerView) findViewById(R.id.recV);
  
          list = new ArrayList&lt;CounterElement&gt;();
  
          mAdapter = new CounterElementAdapter(list);
          RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
          recV.setLayoutManager(mLayoutManager);
          recV.setItemAnimator(new DefaultItemAnimator());
          recV.setAdapter(mAdapter);
  
          submit.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if(name.getText().toString().length() &gt; 0 &amp;&amp; number.getText().toString().length() &gt; 0) {
                      mAdapter.addElement(new CounterElement(name.getText().toString(), Integer.parseInt(number.getText().toString())));
                  }
              }
          });
  
          nextTurn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  mAdapter.nextTurn();
              }
          });
      }
  } 
  
  </code></pre>
  
  <pre><code>public class CounterElementAdapter extends RecyclerView.Adapter&lt;CounterElementAdapter.MyViewHolder&gt; {
  
      private List&lt;CounterElement&gt; elementList;
  
      public class MyViewHolder extends RecyclerView.ViewHolder {
  
          public TextView name, counter;
  
          public MyViewHolder(View view) {
              super(view);
              name = view.findViewById(R.id.name);
              counter = view.findViewById(R.id.counter);
          }
      }
  
  
      public CounterElementAdapter(List&lt;CounterElement&gt; elementList) {
          this.elementList = elementList;
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.element, parent, false);
  
          return new MyViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
          CounterElement ce = elementList.get(position);
          holder.name.setText(ce.getName());
          holder.counter.setText(ce.getDuration());
      }
  
      @Override
      public int getItemCount() {
          return elementList.size();
      }
  
      public void addElement(CounterElement ce){
          elementList.add(ce);
          notifyDataSetChanged();
      }
  
      public void nextTurn(){
          for(CounterElement ce : elementList){
              if(ce.getStatus() &gt;= 1)
                  ce.setStatus(ce.getStatus() - 1);
              else {
                  elementList.remove(elementList.indexOf(ce));
                  notifyDataSetChanged();
              }
          }
      }
  }
  </code></pre>
  
  <p>Thanks in advance</p>