title: how to dynamically keep on adding data to a custom ArrayList from a single EditText
body: <p>I have an EditText in a fragment where user enters something and OnClick the data is added to a custom ArrayList. Then another button which takes to a ListView fragment where all data should be listed but can only see the latest item entered by the user.</p>
  
  <p><strong>Code for adding data in button's OnClick, I think this is where I am doing wrong</strong></p>
  
  <pre><code>EditText timeText = (EditText) getView().findViewById(
                          R.id.dateTimeEText);
  
                  EditText entryText = (EditText) getView().findViewById(
                          R.id.diaryEntryEText);
                  String timeEntry = timeText.getText().toString();
  
                  String entryEntered = entryText.getText().toString();
  
                  ArrayList&lt;DiaryLogs&gt; entryLogs = new ArrayList&lt;DiaryLogs&gt;();
  
                  DiaryLogs dl = new DiaryLogs(1, timeEntry, entryEntered);
                  entryLogs.add(dl);
  </code></pre>
  
  <p><strong>Other codes below</strong></p>
  
  <p><strong>Custom Object Class DiaryLogs</strong></p>
  
  <pre><code>public class DiaryLogs {
  
      //public static ArrayList&lt;DiaryLogs&gt; entryLogs;
  
      String timeEntry, entryEntered;
      int day;
  
      // single constructor that takes an integer and two string
      public DiaryLogs(int day, String timeEntry, String entryEntered) {
          super();
          this.day = day;
          this.timeEntry = timeEntry;
          this.entryEntered = entryEntered;
  
      }
  
      public String getTimeEntry() {
          return timeEntry;
      }
  
      public void setTimeEntry(String timeEntry) {
          this.timeEntry = timeEntry;
      }
  
      public String getEntryEntered() {
          return entryEntered;
      }
  
      public void setEntryEntered(String entryEntered) {
          this.entryEntered = entryEntered;
      }
  
      public int getDay() {
          return day;
      }
  
      public void setDay(int day) {
          this.day = day;
      }
  
      @Override
      public String toString() {
          // TODO Auto-generated method stub
          return this.timeEntry + "\n" + this.entryEntered;
  
  
      }
  
  
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  <strong>Class Monday_fragment</strong></p>
  
  <pre><code>public class Monday_fragment extends Fragment {
  
      public ArrayList&lt;String&gt; myStringList;
      Bundle bundle;
      ArrayList&lt;DiaryLogs&gt; entryLogs;
      EditText timeText;
      EditText entryText;
      DiaryLogs dl;
      String timeEntry;
      String entryEntered;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          return inflater.inflate(R.layout.monday_fragment, container, false);
  
      }
  
      @Override
      public void onViewCreated(View view, Bundle savedInstanceState) {
          currentDateTime();
          super.onViewCreated(view, savedInstanceState);
  
      }
  
      public void currentDateTime() {
          EditText timeText = (EditText) getView().findViewById(
                  R.id.dateTimeEText);
          SimpleDateFormat df = new SimpleDateFormat("d/M/yyyy:H:m");
          String dateTime = df.format(Calendar.getInstance().getTime());
          timeText.setText(dateTime);
      }
  
      public ArrayList&lt;String&gt; toStringList(Collection&lt;DiaryLogs&gt; entryLogs) {
          ArrayList&lt;String&gt; stringList = new ArrayList&lt;String&gt;();
  
          for (DiaryLogs myobj : entryLogs) {
              stringList.add(myobj.toString());
          }
  
          return stringList;
      }
  
      @Override
      public void onStart() {
          entryLogs = new ArrayList&lt;DiaryLogs&gt;();
          timeText = (EditText) getView().findViewById(R.id.dateTimeEText);
  
          entryText = (EditText) getView().findViewById(R.id.diaryEntryEText);
  
          Button saveBtn = (Button) getView()
                  .findViewById(R.id.saveDiaryEntryBtn);
          saveBtn.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
  
                  timeEntry = timeText.getText().toString();
  
                  entryEntered = entryText.getText().toString();
  
                  dl = new DiaryLogs(1, timeEntry, entryEntered);
  
                  entryLogs.add(dl);
                  //convert entryLogs to string array list
                  myStringList = toStringList(entryLogs);
  
                  Toast.makeText(getActivity(), "Entry added \n" + dl,
                          Toast.LENGTH_SHORT).show();
                          entryText.setText("");
  
  
  
  
  
  
              }
  
          }
  
          );
          System.out.println(entryLogs);
  
          Button showBtn = (Button) getView().findViewById(
                  R.id.showDiaryEntriesBtn);
          showBtn.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
  
                  if (myStringList != null) {
                      bundle = new Bundle();
                      FragmentManager fragmentManager = getFragmentManager();
                      FragmentTransaction fragmentTransaction = fragmentManager
                              .beginTransaction();
                      Monday_list_fragment mlf = new Monday_list_fragment();
  
                      bundle.putStringArrayList("list", myStringList);
                      mlf.setArguments(bundle);
  
                      fragmentTransaction.replace(android.R.id.content, mlf);
                      fragmentTransaction.commit();
                  }
                  if (myStringList == null) {
                      Toast.makeText(getActivity(),
                              "No entry have been added yet", Toast.LENGTH_SHORT)
                              .show();
                  }
              }
          });
  
          super.onStart();
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
      }
  
  }
  </code></pre>
  
  <p><strong>Class Monday_list_fragment</strong></p>
  
  <pre><code>        public class Monday_list_fragment extends ListFragment {
      ArrayList&lt;String&gt; logs;
      Bundle bundle;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          return inflater
                  .inflate(R.layout.monday_list_fragment, container, false);
  
      }
  
      @Override
      public void onViewCreated(View view, Bundle savedInstanceState) {
  
          super.onViewCreated(view, savedInstanceState);
          bundle = this.getArguments();
          if (bundle != null) {
              logs = bundle.getStringArrayList("list");
  
              ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(
                      getActivity(), android.R.layout.simple_list_item_1, logs);
              setListAdapter(adapter);
  
          }
  
      }
  
  }
  </code></pre>