Problems creating app to consume mail services

1

I'm developing an application that has the objective of consulting prices and ordering times consuming the service of the Post Office. But I'm having trouble implementing the in-app service. How do I transfer data from the entries of the first activity (where I get source zip and zip destination) from the second (Length, width, height, weight, diameter and retrieve in the third, to then perform the service query using the method of the mails. 2

package com.example.diego.precoeprazocorreios;

import java.io.Serializable;

public class Encomenda implements Serializable{

private String cepOrigem;
private String cepDestino;
private int idIcon;
private String codigo;
private String PrazoEntrega;
private String peso;
private String maoPropria;
private String avisoRecibo;
private Double comprimento;
private Double altura;
private Double largura;
private Double valorDeclarado;

public Encomenda(String cepOrigem, String cepDestino, int idIcon, String codigo, String prazoEntrega, String peso, String maoPropria, String avisoRecibo, Double comprimento, Double altura, Double largura, Double valorDeclarado) {
    this.cepOrigem = cepOrigem;
    this.cepDestino = cepDestino;
    this.idIcon = idIcon;
    this.codigo = codigo;
    PrazoEntrega = prazoEntrega;
    this.peso = peso;
    this.maoPropria = maoPropria;
    this.avisoRecibo = avisoRecibo;
    this.comprimento = comprimento;
    this.altura = altura;
    this.largura = largura;
    this.valorDeclarado = valorDeclarado;
}

public String getCodigo() {
    return codigo;
}

public void setCodigo(String codigo) {
    this.codigo = codigo;
}

public String getPrazoEntrega() {
    return PrazoEntrega;
}

public int getIdIcon() {
    return idIcon;
}

public void setIdIcon(int idIcon) {
    this.idIcon = idIcon;
}

public void setPrazoEntrega(String prazoEntrega) {
    PrazoEntrega = prazoEntrega;
}

public String getPeso() {
    return peso;
}

public void setPeso(String peso) {
    this.peso = peso;
}

public String getMaoPropria() {
    return maoPropria;
}

public void setMaoPropria(String maoPropria) {
    this.maoPropria = maoPropria;
}

public String getAvisoRecibo() {
    return avisoRecibo;
}

public void setAvisoRecibo(String avisoRecibo) {
    this.avisoRecibo = avisoRecibo;
}

public Double getComprimento() {
    return comprimento;
}

public void setComprimento(Double comprimento) {
    this.comprimento = comprimento;
}

public Double getAltura() {
    return altura;
}

public void setAltura(Double altura) {
    this.altura = altura;
}

public Double getLargura() {
    return largura;
}

public void setLargura(Double largura) {
    this.largura = largura;
}

public Double getValorDeclarado() {
    return valorDeclarado;
}

public void setValorDeclarado(Double valorDeclarado) {
    this.valorDeclarado = valorDeclarado;
}

public String getCepOrigem() {
    return cepOrigem;
}

public void setCepOrigem(String cepOrigem) {
    this.cepOrigem = cepOrigem;
}

public String getCepDestino() {
    return cepDestino;
}

public void setCepDestino(String cepDestino) {
    this.cepDestino = cepDestino;
}


}

First activity

package com.example.diego.precoeprazocorreios;

import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btnProximo1 = (Button) findViewById(R.id.proximo1);
    btnProximo1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            validarCampos();
        }
    });
}

public void validarCampos() {

    EditText cepOrigem = (EditText) findViewById(R.id.origem);
    EditText cepDestino = (EditText) findViewById(R.id.destino);

    String cepOri = cepOrigem.getText().toString();
    String cepDes = cepDestino.getText().toString();
    String padrao = "\d{8}";

    if (!cepOri.matches(padrao)) {
        cepOrigem.requestFocus();
        Toast toast = Toast.makeText(getApplicationContext(), "CEP inválido", Toast.LENGTH_LONG);
        toast.show();
    } else if (!cepDes.matches(padrao)) {
        cepDestino.requestFocus();
        Toast toast = Toast.makeText(getApplicationContext(), "CEP inválido", Toast.LENGTH_LONG);
        toast.show();
    } else {
        Encomenda enc = new Encomenda(cepOrigem.getText().toString(), cepDestino.getText().toString());
        Intent myIntent = new Intent(MainActivity.this, SegundaActivity.class);
        myIntent.putExtras("objeto", enc);
        startActivity(myIntent);
    }
}
}
    
asked by anonymous 08.11.2017 / 22:47

1 answer

1

Add to your class a constructor like this:

public Encomenda() {
}

After you fill in the fields and call the other activity, fill in the fields using get and set. Put this snippet in else:

else {
        Encomenda enc = new Encomenda();
        enc.setCepOrigem(cepOrigem.getText().toString());
        enc.setCepDestino(cepDestino.getText().toString());
        Intent myIntent = new Intent(MainActivity.this, SegundaActivity.class);
        myIntent.putExtras("objeto", enc);
        startActivity(myIntent);
    }

Now, in the other activity, when filling in the other fields, before calling activity, read this variable from the bundle, fill in the new fields using get and set and then move on to the next one, such as first to second . Example:

Encomenda enc = getIntent().getSerializableExtra("objeto");
enc.setComprimento(); //Ai le do EditText como na primeira Activity.

//Aqui vc vai chamar a activity 3
Intent myIntent = new Intent(MainActivity.this, TerceiraActivity.class);
myIntent.putExtras("objeto", enc);
startActivity(myIntent);

In ThirdActivity, you will read in the same way as in the second, fill in and move to the webservice call.

    
09.11.2017 / 14:37