title: String ArrayList using Collections
body: <p>My main <code>activity</code> has multiple <code>ArrayLists</code> and <code>Arrays</code>. When you click the Smoked Cigarette button, the application logs certain information in the <code>ArrayList</code>. One of the <code>ArrayLists</code> locationsSmoked holds all the locations you've smoked at. My task is to make an <code>activity</code> that displays in a <code>ListView</code> the location you smoked at, and how many times you smoked there.
  If you display the locationsSmoked <code>array</code> currently it will look like this</p>
  
  <p>Home<br>
  Home<br> 
  Home<br> 
  Work<br> 
  Work<br> 
  School<br> 
  School<br></p>
  
  <p>and so on and so forth. I need to loop through this <code>array</code> to display the amount of times each <code>string</code> is called and give the <code>integer</code> value. I then need to combine the <code>integer</code> with the matching <code>string</code>. In a parallel <code>array</code> or multidimensional <code>array</code> to display the information in another <code>activity</code> named Locations in that <code>activity</code>'s listview
  So it looks like this</p>
  
  <p>Home: 3<br>
  Work: 2<br>
  School: 2<br></p>
  
  <p>It should be noted that even though you should never hard code elements, in this situation I literally am not allowed to because the <code>ArrayList</code> of locations will be constantly growing. There is another <code>activity</code> I've already completed that allows the user to add new locations to the existing <code>ArrayList</code>
  I think the code I'm about to list below from my model.java and my locations.java is for the most part accurate. However nothing displays in the <code>listview</code> when i go to the <code>activity</code>. </p>
  
  <p>So if that was confusing in any please let me know and I'll ask more specifically. </p>
  
  <p>Thanks for any help you can offer. </p>
  
  <p>Model.java    </p>
  
  <pre><code>import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Collections;
  import java.util.GregorianCalendar;
  
  public class Model implements Serializable {
  public static final int END_MORNING = 11;  // 11:00AM, inclusive
  public static final int END_AFTERNOON = 16;  // 4:00PM, inclusive
  private int locNumber;
  private String locName;
  
  private GregorianCalendar startDate;
  
  private ArrayList&lt;GregorianCalendar&gt; datesSmoked = new ArrayList&lt;GregorianCalendar&gt;();
  private ArrayList&lt;String&gt; locationsSmoked = new ArrayList&lt;String&gt;();
  private ArrayList&lt;String&gt; locations = new ArrayList&lt;String&gt;();
  private ArrayList&lt;String&gt; allIncidents = new ArrayList&lt;String&gt;();
  private ArrayList&lt;String&gt; test  = new ArrayList&lt;String&gt;();
  
  public String [] defaultLocations = {"Home", "Work", "Commuting", "School", "Bar", "Restaurant", "Social Gathering", "Other"};
  public String [] eachSmoked;
  
  
  public Model(GregorianCalendar date){
      startDate = date;
  
      for (String s : this.defaultLocations) {            
          locations.add(s);
      }           
  }
  
  public Model(){
      this(new GregorianCalendar()); // now
  }   
  
  
  public void setAllIncidentsArray() {        
      this.allIncidents.add(datesSmoked.toString());
      this.allIncidents.add(locationsSmoked.toString());
  }
  
  public void setEachSmoked() {
      for (int i = 0; i &lt; locationsSmoked.size(); i++) {
          locNumber = Collections.frequency(locationsSmoked, locationsSmoked.get(i));
          locName = locations.get(i);
          test.add(i, locNumber + locName);
      }
  }
  
  public ArrayList&lt;String&gt; getEachSmoked() {              
      return this.test;
  }
  
  public ArrayList&lt;String&gt; getAllIncidentsArray() {
      return this.allIncidents;
  }
  
  public ArrayList&lt;String&gt; getlocationsArray() {
      return this.locations;
  }
  
  public ArrayList&lt;String&gt; getLocationsSmokedArray() {
      return this.locationsSmoked;
  }
  
  public ArrayList&lt;GregorianCalendar&gt; getDatesSmokedArray() {
      return this.datesSmoked;
  }
  
  public void incrementCount(String location) {   
      this.datesSmoked.add(new GregorianCalendar());  // now
      this.locationsSmoked.add(location);     
  }
  
  public int getTodayCount() {
      GregorianCalendar now = new GregorianCalendar();
      int todayDayOfYear = now.get(Calendar.DAY_OF_YEAR);
  
      int count = 0;
      for (GregorianCalendar day : this.datesSmoked)
          if (day.get(Calendar.DAY_OF_YEAR) == todayDayOfYear)
              count++;
  
      return count;
  }
  
  public int getTotalCount() {
      return this.datesSmoked.size();
  }
  
  public double getAverage() {
      if (getDays() &gt; 0)
          return (double) getTotalCount() / getDays();
      else
          return 0.0;
  }
  
  public int getDays() {
      return (new GregorianCalendar()).get(Calendar.DAY_OF_YEAR) - startDate.get(Calendar.DAY_OF_YEAR) + 1;
  }
  
  public int getMorning() {
      int count = 0;
      for (GregorianCalendar date : this.datesSmoked)
          if (date.get(Calendar.HOUR_OF_DAY) &lt;= END_MORNING)
              count++;
  
      return count;
  }
  
  public int getAfternoon() {
      int count = 0;
      for (GregorianCalendar date : this.datesSmoked)
          if (date.get(Calendar.HOUR_OF_DAY) &gt; END_MORNING &amp;&amp; date.get(Calendar.HOUR_OF_DAY) &lt;= END_AFTERNOON)
              count++;
  
      return count;
  }
  
  public int getEvening() {
      int count = 0;
      for (GregorianCalendar date : this.datesSmoked)
          if (date.get(Calendar.HOUR_OF_DAY) &gt; END_AFTERNOON)
              count++;
  
      return count;
  }
  }
  </code></pre>
  
  <p>Locations.java (locations Activity)</p>
  
  <pre><code>import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  
  public class LocationActivity extends Activity {
  
  public static final String SMOKIN_DATA_FILE = "smokin.dat";
  
  public static Model model = null;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_location);
  
      restoreModel();
  
      ListView listView = (ListView) findViewById(R.id.location_listview_Id);
      ArrayAdapter&lt;String&gt; listAdapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_list_item_1, model.getEachSmoked());        
      listView.setAdapter(listAdapter);       
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_location, menu);
      return true;
  }
  
  public void restoreModel() {
      // Restore from disk, or start with an empty model
      try {
          ObjectInputStream ois = new ObjectInputStream(
                  openFileInput(SMOKIN_DATA_FILE));
  
          model = (Model) ois.readObject();
          ois.close();
      } catch (Exception e) {
          Log.v("*** DEBUG ***", "Error writing to file: " + e);
          model = new Model();
      }
  }    
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle item selection
      switch (item.getItemId()) {
  
      case R.id.menu_home_Id:
          Intent homeIntent = new Intent(this, MainActivity.class);
          startActivity(homeIntent); ;
          return true;
  
      case R.id.menu_all_incidents_Id:
          Intent allIncidentsIntent = new Intent(this, AllIncidentsActivity.class);
          startActivity(allIncidentsIntent); ;
          return true;
  
      case R.id.menu_edit_locations_Id:
          Intent editLocationsIntent = new Intent(this, EditLocationsActivity.class);
          startActivity(editLocationsIntent); ;
          return true;
      default:
          return super.onOptionsItemSelected(item);
      }
  
  }
  }
  </code></pre>