Example #1
0
  private void fillListView() {

    Cursor c = null;

    if (sortOrder == 1) {
      c = itemDao.getCursorOfAllItemsByPriority();
    } else if (sortOrder == 2) {
      c = itemDao.getCursorOfAllItemsByPrice();
    } else {
      c = itemDao.getCursorOfAllItems();
    }
    startManagingCursor(c);
    String[] from =
        new String[] {
          itemDao.KEY_NAME,
          itemDao.KEY_LOCATION,
          itemDao.KEY_QUANTITY,
          itemDao.KEY_UNITPRICE,
          ItemDao.KEY_PRIORITY
        };
    int[] to = new int[] {R.id.name, R.id.location, R.id.quantity, R.id.unitprice, R.id.priority};
    SimpleCursorAdapter items = new SimpleCursorAdapter(this, R.layout.item_table_row, c, from, to);
    items.setViewBinder(new RowViewBinder());
    ListView list = getListView();
    list.setAdapter(items);
    list.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(IkeaCart.this, ItemEdit.class);
            intent.putExtra(ItemDao.KEY_ROWID, id);
            startActivityForResult(intent, ACTIVITY_EDIT);
          }
        });
  }
Example #2
0
  public CartService(ItemDao itemDao, Preference pref) {

    Cursor cursor = itemDao.getCursorOfAllItems();
    totalItems = cursor.getCount();
    totalCost = 0;
    if (totalItems > 0) {
      calcCost(cursor, pref);
    }
    cursor.close();
  }