date problem

Asked

Viewed 89 times

0

in my application when I make a request for sale, should inform the date of the order and the date of issue, the date of the order I pick up automatically, already the date of issue should be filled in manually.

After the Inserts, I export the AVD database and open in Sqlite experts and no date appears, all appear as "1899-12-30"

inserir a descrição da imagem aqui

Code:

insert button of the request:

Button confirma = (Button) findViewById(R.id.btnConfirmar);
    confirma.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final BancoController crud = new BancoController(getBaseContext());

            EditText data = (EditText) findViewById(R.id.edtData);
            EditText emissao = (EditText) findViewById(R.id.edtEmissao);
            EditText obs = (EditText) findViewById(R.id.edtObs);

            String dataString = data.getText().toString();
            String emissaoString = emissao.getText().toString();
            String obsString = obs.getText().toString();
            String resultadoPe;
            String resultadoPp = null;

            Spinner spClientes = (Spinner) findViewById(R.id.spCliente);
            Spinner spCarteira = (Spinner) findViewById(R.id.spCarteira);
            Spinner spPagamentos = (Spinner) findViewById(R.id.spPagamento);

            SQLiteCursor dadosClientes = (SQLiteCursor) spClientes.getAdapter().getItem(
                    spClientes.getSelectedItemPosition());

            SQLiteCursor dadosCarteira = (SQLiteCursor) spCarteira.getAdapter().getItem(
                    spCarteira.getSelectedItemPosition());

            SQLiteCursor dadosPagamentos = (SQLiteCursor) spPagamentos.getAdapter().getItem(
                    spPagamentos.getSelectedItemPosition());

            String idCliente = String.valueOf(dadosClientes.getInt(0));
            String idCarteira = String.valueOf(dadosCarteira.getInt(0));
            String idPagamento = String.valueOf(dadosPagamentos.getInt(0));

            crud.op = 2;

            resultadoPe = crud.insereDados(null, null, null, null, null, null, null, null,
                    null, null, null, null, idCliente, idPagamento, idCarteira, dataString,
                    emissaoString, obsString, null, null, null, null, null);

            Toast.makeText(getApplication(), resultadoPe, Toast.LENGTH_LONG).show();

Entered data from the application:

public String insereDados
        (String nome, String apelido, String cpf, String rg, String endereco, String bairro,
         String municipio, String uf, String cep, String email, String fone, String cla,
         String par, String car, String cpag, String data, String emissao, String obs, String ped,
         String pro, String quantidade, String unitario, String item /**String lpPcodigo,
         String lpDescri, String lpQtd, String lpPreco*/){

    long resultadoC = -1;
    long resultadoPe = -1;
    long resultadoPr = -1;
    //long resultadoLp = -1;
    db = banco.getWritableDatabase();


    switch (op){
        case 1://Insere cliente:
            ContentValues cvc;
            cvc = new ContentValues();

            cvc.put(CriaBanco.getParNome(), nome);
            cvc.put(CriaBanco.getParApelido(), apelido);
            cvc.put(CriaBanco.getParCpf(), cpf);
            cvc.put(CriaBanco.getParRg(), rg);
            cvc.put(CriaBanco.getParEndereco(), endereco);
            cvc.put(CriaBanco.getParBairro(), bairro);
            cvc.put(CriaBanco.getParMunicipio(), municipio);
            cvc.put(CriaBanco.getParUf(), uf);
            cvc.put(CriaBanco.getParCep(), cep);
            cvc.put(CriaBanco.getParEmail(), email);
            cvc.put(CriaBanco.getParFone(), fone);

            resultadoC = db.insert(CriaBanco.getParTabela(), null, cvc);
            break;

        case 2://Insere Pedido
            ContentValues cvpe;
            cvpe = new ContentValues();

            cvpe.put(CriaBanco.getClaId(), cla);
            cvpe.put(CriaBanco.getPparId(), par);
            cvpe.put(CriaBanco.getCarId(), car);
            cvpe.put(CriaBanco.getCpagId(), cpag);
            cvpe.put(CriaBanco.getPedData(), data);
            cvpe.put(CriaBanco.getPedEmissao(), emissao);
            cvpe.put(CriaBanco.getPedObs(), obs);

            resultadoPe = db.insert(CriaBanco.getPedTabela(), null, cvpe);
            break;

        case 3: // Insere Pedido Produto

            ContentValues cvpr;
            cvpr = new ContentValues();

            cvpr.put(CriaBanco.getPppedId(), ped);
            cvpr.put(CriaBanco.getPpproId(), pro);
            cvpr.put(CriaBanco.getPproQnt(), quantidade);
            cvpr.put(CriaBanco.getPproUnit(), unitario);
            cvpr.put(CriaBanco.getPproItem(), item);

            resultadoPr = db.insert(CriaBanco.getPprodTabela(), null, cvpr);
            break;

    }
    db.close();

    if (resultadoC != -1){
        return "Cliente inserido com sucesso!";
    }else if(resultadoPe != -1 || resultadoPr != -1){
        return "Pedido realizado com sucesso!";
    }/**else if(resultadoLp != -1) {
        return "Produto adicionado a lista com sucesso!";
    }*/else{
        return "Erro ao inserir registro (cliente/pedido)!";
    }
}

Date edittext use both on order date and on issue date.

another question, has how to modify date formatting?

for example, it appears automatically:

inserir a descrição da imagem aqui

appears May 13, 2016, can not modify and appear as 13/05/2016?

and can modify with the code to when inserting the date modify the "/" by "-"?

thanks since you

---EDIT---

how I automatically pick up the date:

final String currentDataTimeString = DateFormat.getDateInstance().format(new Date());

1 answer

1


try as follows:

String str = new SimpleDateFormat("dd/"+"MM"+"/yyyy").format(new Date());
  • worked out, but still keeps saving the date wrong in the bank, I think it’s because of the bars...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.