title: Android: Why the listview.add function is always adding elements on position 1 in the list
body: <p>I am trying to implement two activities that are exchanging information between them using intents.
  Activity#1 contains an empty listview and a button that starts Activity#2 when pressed. On Activity#2 I have some textbox fields and a "Save" button that sends through intent.putExtra methods information to Activity#1.
  The issue is that each time I try to create a new View with the information passed by Activity#2, the list is overriding the first element.</p>
  
  <p>You can see below the OnCreate method from Activity#1:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_list_explorer);
      notesList = findViewById(R.id.listviewNotes);
  
          FloatingActionButton myFab = this.findViewById(R.id.fabAddNote);
          myFab.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              Intent intentNoteEditor = new Intent(getApplicationContext(), NoteEditor.class);
              startActivity(intentNoteEditor);
              //Log.i("Lista",notesList.getCount()+"");
          }
      });
          Intent intent =getIntent();
          Bundle extras =intent.getExtras();
          if(extras!=null){
              if(extras.containsKey("isnewNote")){
                  isnewElement=extras.getBoolean("isnewNote",false);
              }
          }
      if(isnewElement==true){
  
          //***************Fetch data from intent***************//
              notetext = intent.getStringExtra("noteText");
              notecolor = intent.getStringExtra("noteColor");
              notelocation = intent.getStringExtra("noteLocation");
              notereminder = intent.getStringExtra("noteReminder");
              Note receivednote = new Note(notetext, notecolor, notereminder, notelocation);
              MyAdapter adapter = new MyAdapter(this, R.layout.list_item, notesArray);
              notesArray.add(receivednote);
              notesList.setAdapter(adapter);
          //***************End Fetch data from intent***********//
      }
  }
  </code></pre>
  
  <p>I am also attaching the custom adapter implemented.</p>
  
  <p>public class MyAdapter extends ArrayAdapter {</p>
  
  <pre><code>private Context mContext;
  private int mResource;
  private ArrayList&lt;Note&gt; mNotes = new ArrayList&lt;&gt;();
  private String TAG = "Adapter Class";
  
  public MyAdapter(@NonNull Context context, int resource, ArrayList&lt;Note&gt; objects) {
      super(context, resource, objects);
      mContext = context;
      mResource = resource;
      mNotes = objects;
  }
  
  @Override
  public int getCount() {
      return mNotes.size();
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      View listItem =convertView;
      if(listItem==null){
          listItem=LayoutInflater.from(mContext).inflate(mResource,parent,false);
  
      Note currentNote = mNotes.get(position);
      String text = mNotes.get(position).getText();
      String color = mNotes.get(position).getColor();
      String location = mNotes.get(position).getLocation();
      String reminder = mNotes.get(position).getReminder();
  
      TextView nttxt = listItem.findViewById(R.id.noteText);
      TextView ntcolor = listItem.findViewById(R.id.textcolor);
      TextView ntrem = listItem.findViewById(R.id.reminder);
      TextView ntlocat = listItem.findViewById(R.id.location);
  
      nttxt.setText(text);
      ntcolor.setText(color);
      ntrem.setText(reminder);
      ntlocat.setText(location);
      }
      return listItem;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I logged the list size and it is always 1. For some reason, it does not keep the current elements after the Activity#2 is launched.</p>
  
  <p>Any advice will be appreciated. </p>