예제 #1
0
  public void guardarGasto(View view) {
    if (tvMonto.getText().toString().equals("")) return;

    int monto = Integer.parseInt(tvMonto.getText().toString());
    Spinner spinnerCategoria = (Spinner) findViewById(R.id.categoria);
    Categoria categoria = categorias.get(spinnerCategoria.getSelectedItemPosition());
    TextView tvSubcategoria = (TextView) findViewById(R.id.subcategoria);
    String subcategoria = tvSubcategoria.getText().toString();

    subcategoria = subcategoria.toLowerCase();
    subcategoria = subcategoria.trim();

    gasto.setMonto(monto);
    gasto.setCategoria(categoria);
    gasto.setSubcategoria(subcategoria);
    gasto.setSincronizado(false);

    GastosDbAdapter gastosDbAdapter = new GastosDbAdapter(this);
    gastosDbAdapter.abrir();
    gastosDbAdapter.actualizarGasto(gasto);
    gastosDbAdapter.cerrar();

    tvMonto.setText("");
    spinnerCategoria.setSelection(0);
    tvSubcategoria.setText("");

    tvMonto.clearFocus();

    Toast.makeText(this, "Gasto guardado ", Toast.LENGTH_LONG).show();
    this.finish();
  }
예제 #2
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Bundle b = getIntent().getExtras();
    int id = b.getInt("id");

    categoriasDbAdapter = new CategoriasDbAdapter(this);
    categoriasDbAdapter.abrir();

    this.context = this;

    gastoDBAdapter = new GastosDbAdapter(this);
    gastoDBAdapter.abrir();
    gasto = gastoDBAdapter.obtenerGasto(id);

    cargarCategorias();

    tvMonto = (TextView) findViewById(R.id.monto);
    tvMonto.setText(String.valueOf(gasto.getMonto()));
    TextView tvSubcategoria = (TextView) findViewById(R.id.subcategoria);
    tvSubcategoria.setText(gasto.getSubcategoria());
  }
예제 #3
0
  private void cargarCategorias() {
    categorias = categoriasDbAdapter.obtenerCategorias();
    Iterator<Categoria> iterator = categorias.iterator();
    int position = -1;
    while (iterator.hasNext() && position == -1) {
      Categoria cat = iterator.next();
      if (cat.getId() == gasto.getCategoria().getId()) position = categorias.indexOf(cat);
    }

    Spinner spinner = (Spinner) findViewById(R.id.categoria);
    ArrayAdapter<Categoria> adapter =
        new ArrayAdapter<Categoria>(this, android.R.layout.simple_spinner_item, categorias);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(position);
  }