예제 #1
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lista_comidas2);

    String categoria = null;
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      categoria = extras.getString("categoria");
    }

    // La URI content://contacts/people consulta todos los contactos
    Uri uriContacts = AlimentoProvider.CONTENT_URI;

    // Cursor c = managedQuery(uriContacts, null, null, null, null);

    DatabaseHelper usdbh = new DatabaseHelper(this, "effective_rutine.db", null, 1);

    SQLiteDatabase db = usdbh.getWritableDatabase();

    Cursor c;
    if (categoria.equals(null)) {
      c =
          db.rawQuery(
              "select id_alimento as _id,* from catalogo_alimento c, alimento a  where c.id_catalogo=a.id_catalogo",
              null);
    } else {
      c =
          db.rawQuery(
              "select id_alimento as _id,* from catalogo_alimento c, alimento a  where c.id_catalogo=a.id_catalogo and c.id_catalogo_padre='"
                  + categoria
                  + "'",
              null);
    }
    String[] columns =
        new String[] {
          AlimentoProvider.NOMBRE,
          AlimentoProvider.CALORIAS_KCAL,
          AlimentoProvider.DESCRIPCION,
          AlimentoProvider.CANTIDAD_G,
          AlimentoProvider.ID_CATALOGO,
          AlimentoProvider.GRASAS_G,
          AlimentoProvider.PROTEINAS_G,
          AlimentoProvider.CARBOHIDRATOS_G,
          AlimentoProvider._ID
        };
    int[] views = new int[] {R.id.nombre, R.id.tcalorias, R.id.porcion};

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row2, c, columns, views);
    miLista = this.getListView();
    miLista.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    // this.getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    miLista.setAdapter(adapter);
    usdbh.close();
  }
예제 #2
0
  public void updateRutina(String hoy) {
    String sum = "0";
    // select sum (d.calorias_kcal) as sum from detalle_rutina_alimento d,alimento a,rutina_alimento
    // r where d.id_alimento=a.id_alimento and d.id_rutina_alimento=r.id_rutina_alimento and
    // r.id_regimen=2
    DatabaseHelper usdbh = new DatabaseHelper(this, "effective_rutine.db", null, 1);

    SQLiteDatabase db = usdbh.getWritableDatabase();

    String regimen = null;
    String codigo = null;
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      regimen = extras.getString("regimen");
      codigo = extras.getString("codigo");
    }

    Cursor c =
        db.rawQuery(
            "select sum (d.calorias_kcal) as sum from detalle_rutina_alimento d,alimento a,rutina_alimento r where d.id_alimento=a.id_alimento and d.id_rutina_alimento=r.id_rutina_alimento and r.id_regimen="
                + regimen
                + " and r.tiempo_inicio='"
                + hoy
                + "'",
            null);

    if (c.moveToFirst()) {
      sum = c.getString(c.getColumnIndex("sum"));
      Log.d("my tag2", "yo sumo ahora " + sum);
    }
    if (sum == null) {
      sum = "0";
      Log.d("my tag2", "no sumo nada por eso soy un " + sum);
    }
    ContentValues values = new ContentValues();
    values.put(RutinaAlimentoProvider.TOTAL_CALORIAS_KCAL, sum);

    String uriString =
        "content://"
            + RutinaAlimentoProvider.PROVIDER_NAME
            + "/"
            + RutinaAlimentoProvider.ENTIDAD
            + "/"
            + codigo;
    Uri CONTENT_URI = Uri.parse(uriString);
    getContentResolver().update(CONTENT_URI, values, null, null);

    usdbh.close();
  }