Android Open Source - groceryhelper Item List






From Project

Back to project page groceryhelper.

License

The source code is released under:

Apache License

If you think the Android project groceryhelper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.munner.groceryhelper;
/*from ww w  .  j  a  va2 s.c  om*/
import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

public class ItemList implements Parcelable{
  
  ArrayList<Item> al;
  public ItemList() {
    al = new ArrayList<Item>();
  }

  @Override
  public int describeContents() {
    return 0;
  }
  
  @Override
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeList(al);
  }

  public ArrayList<Item> getarrayList() {
    return al;
  }
  
  public String[] getStringList() {
    int i;
    int j = al.size();
    String[] sList = new String[j];
    for (i=0; i < al.size(); i++) {
      sList[i] = al.get(i).getCost() + " " + al.get(i).getCategory();
    }
    return sList;
  }
  
  public double getTotal() {
    double total = 0.0;
    int i;
    for (i = 0; i < al.size(); i++) {
      total += al.get(i).getCost();
    }
    return round(total);
  }

  public double getCost(String category) {
    int i;
    double total = 0.0;
    for (i= 0; i < al.size(); i++) {
      if (al.get(i).getCategory().equals(category)) {
        total += al.get(i).getCost();
      }
    }
    return round(total);
  }

  public void addItem(double cost, String category) {
    Item it = new Item(cost, category);
    al.add(it);
  }
  
  public void removeItem(int index) {
    al.remove(index);
  }
  
  private double round(double value) {
    return Math.floor(value * 100) / 100;
  }

  public void clear() {
    for (; 0 < al.size();) {
      al.remove(0);
    }
  }

  public int size() {
    // TODO Auto-generated method stub
    return al.size();
  }
  
}




Java Source Code List

com.munner.groceryhelper.BuildConfig.java
com.munner.groceryhelper.ItemList.java
com.munner.groceryhelper.Item.java
com.munner.groceryhelper.ListActivity.java
com.munner.groceryhelper.MainActivity.java
com.munner.groceryhelper.Remove.java