title: RecyclerView Adapter List<E> get 0
body: <p>I am new in android development. I am getting a problem, I have create simple application in which I have RecyclerView in MainActivity. I try to Drag and Drop position. But when I move from MainActivity to CompleteList_activity and come to again MainActivity and try to Drag and drop i got ArrayOutOfBound error because List value get 0 in 
   public void positionchange(int fromPosition, int toPosition) method.</p>
  
  <p>MainActivity : </p>
  
  <pre><code>package com.example.marmeto.todolist;
  
  import android.content.Intent;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.helper.ItemTouchHelper;
  import android.view.View;
  import android.widget.ImageButton;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity implements View.OnClickListener{
  
      DBHelper db;
  
      ImageButton btn_addtodolist,btn_completelist;
      List&lt;Model&gt; todolist = new ArrayList&lt;&gt;();
      List&lt;Model&gt; adapterList = new ArrayList&lt;&gt;();
      private RecyclerView recyclerView;
      private RecyclerView.LayoutManager layoutManager;
      private ToDoList_Adapter adapter;
      public static final int NEW_WORD_ACTIVITY_REQUEST_CODE = 1;
      Model mToDOItemList = new Model();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          db = new DBHelper(this);
  
          recyclerView = (RecyclerView)findViewById(R.id.recyclerview);
          recyclerView.setHasFixedSize(true);
          layoutManager = new LinearLayoutManager(getApplicationContext());
          recyclerView.setLayoutManager(layoutManager);
  
          btn_addtodolist = (ImageButton) findViewById(R.id.btn_addtodolist);
          btn_completelist = (ImageButton)findViewById(R.id.btn_completedlist);
          btn_addtodolist.setOnClickListener(this);
  
          btn_completelist.setOnClickListener(this);
  
          getValue();
      }
      void getValue(){
          todolist.clear();
  
          todolist = db.getUserDetail();
  
          Collections.sort(todolist, new Comparator&lt;Model&gt;() {
              @Override public int compare(Model p1, Model p2) {
                  return p1.getPosition()- p2.getPosition(); // Ascending
              }
          });
          adapter = new ToDoList_Adapter(todolist,getApplicationContext());
  
          ItemTouchHelper.SimpleCallback callback=new SwipItem(adapter);
          ItemTouchHelper helper=new ItemTouchHelper(callback);
          helper.attachToRecyclerView(recyclerView);
  
          recyclerView.setAdapter(adapter);
          adapter.notifyDataSetChanged();
      }
  
  
  
      @Override
      protected void onResume() {
          super.onResume();
      }
  
      @Override
      protected void onPause() {
          super.onPause();
      }
  
      @Override
      public void onClick(View v) {
  
  
          if (v.getId() == R.id.btn_addtodolist) {
              Intent intent = new Intent(getApplicationContext(), AddToDoList_Activity.class);
              startActivity(intent);
  
          } else {
              Intent intent = new Intent(getApplicationContext(),CompletedActivity.class);
              startActivity(intent);
  
          }
      }
      }
  </code></pre>
  
  <p>AdapterClass:</p>
  
  <pre><code>    package com.example.marmeto.todolist;
      import android.content.Context;
      import android.support.annotation.NonNull;
      import android.support.v7.widget.RecyclerView;
      import android.util.Log;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.Button;
      import android.widget.TextView;
      import android.widget.Toast;
      import java.util.Collections;import java.util.List;
  
         public class ToDoList_Adapter extends             RecyclerView.Adapter&lt;ToDoList_Adapter.ViewHolder&gt; {
  
      List&lt;Model&gt; items;
      private Context context;
  
      public ToDoList_Adapter(List&lt;Model&gt; items, Context context) {
          this.items = items;
          this.context = context;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.todolist_adapter, parent, false);
          ViewHolder viewHolder = new ViewHolder(v);
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(ViewHolder holder, final int position) {
  
          final Model itemlist = items.get(position);
          holder.todoText.setText(itemlist.getPosition()+" "+itemlist.getTitle());
      }
  
  
      @Override
      public int getItemCount() {
          return items.size();
      }
      public void positionchange(int fromPosition, int toPosition)
      {
  
          try {
          Collections.swap(items,fromPosition,toPosition);
  
          DBHelper db = new DBHelper(context);
          db.updateList(items);
           }catch (Exception e)
           {
               e.printStackTrace();
           }
          this.notifyItemMoved(fromPosition,toPosition);
  
  
      }
  
      public void deletePlanet(int pos)
      {
          //GET ID
          try {
              Model p = items.get(pos);
              int id = p.getId();
  
              //DELETE FROM DB
              DBHelper db = new DBHelper(context);
  
              if (db.delete(id)) {
                  items.remove(pos);
                  db.updateList(items);
  
              } else {
                  Toast.makeText(context, "Unable To Delete", Toast.LENGTH_SHORT).show();
              }
              this.notifyItemRemoved(pos);
          }catch (Exception e){
              e.printStackTrace();
          }
  
  
  
  
      }
      class ViewHolder extends RecyclerView.ViewHolder {
  
          public TextView todoText;
          public Button btn_done;
          public ViewHolder(final View itemView) {
              super(itemView);
  
              todoText = (TextView)itemView.findViewById(R.id.todoItem_text);
              btn_done = (Button)itemView.findViewById(R.id.btn_done);
              btn_done.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                      DBHelper db = new DBHelper(context);
                      try {
                          Model p = items.get(getAdapterPosition());
                          db.updateData(p.getId());
                          items.remove(getAdapterPosition());
  
                          db.updateList(items);
                      }catch (Exception e){
                          e.printStackTrace();
                      }
  
                      notifyItemRemoved(getAdapterPosition());
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p>Thanks in advance to help.</p>