How to add fragments in order within an activity with a button?

0

This is the query I have, I have a ContainerActivity that contains an initial fragment, my RelevamientoFragment which is this screen

In the floating button to add that they see the image, I have a case that opens another fragment, in this case my AberturaFragment that is the following screen:

I open this fragment in the following way:

    @Override
public void onClick(View view) {
    int id = view.getId();
    switch (id){
        case R.id.fab:
            animateFAB();
            break;

        case R.id.fab_enviar:
          showDialog();
            break;

        case R.id.fab_agregar:
            SegundaAberturaFragment segundaAberturaFragment = new SegundaAberturaFragment();
            getSupportFragmentManager().beginTransaction().add(R.id.container, segundaAberturaFragment)
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                    .addToBackStack(null).commit();
            break;
    }
}

Up to that point, all right, what I need to do is that, if the user presses the add button again, the opening fragment will be generated (the second screen), but with the fields clean and without that the ones that are being added are deleted, to then send all that in an email, this is the email function that I have right now:

public void enviarEmail() {

    //Inputs de los valores a ser enviados
    EditText fecha = findViewById(R.id.etFecha);
    TextInputEditText obra =  findViewById(R.id.etObra);
    TextInputEditText lugar =  findViewById(R.id.etLugar);
    TextInputEditText color =  findViewById(R.id.etColor);
    TextInputEditText milimetraje =  findViewById(R.id.etMilimetraje);
    Spinner abertura = findViewById(R.id.opciones);
    TextInputEditText largo = findViewById(R.id.etLargo);
    TextInputEditText ancho = findViewById(R.id.etAncho);
    TextInputEditText obs =   findViewById(R.id.etObs);


    String[] TO = {"[email protected]"};

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setData(Uri.parse("mailto:"));
    intent.setType("text/html");
    intent.putExtra(Intent.EXTRA_EMAIL, TO);
    intent.putExtra(Intent.EXTRA_SUBJECT, "Relevamiento");
    intent.putExtra(Intent.EXTRA_TEXT,
            Html.fromHtml(new StringBuilder()
                    .append("<p>Fecha:" + fecha.getText() + "</p>")
                    .append("<p><b>Obra:</b>" + obra.getText() + "</p>")
                    .append("<p><b>Lugar:</b>" + lugar.getText() + "</p>")
                    .append("<p><b>Color de vidrio:</b>" + color.getText() + "</p>")
                    .append("<p><b>Milimetraje:</b>" + milimetraje.getText() + "</p>")
                    .append("<p><b>Tipo de abertura:</b>" + abertura.getSelectedItem() + "</p>")
                    .append("<p><b>Largo:</b>" + largo.getText() + "</p>")
                    .append("<p><b>Ancho:</b>" + ancho.getText() + "</p>")
                    .append("<p><bold>Observacion:</bold>" + obs.getText() + "</p>")
                    .append("<p><b>Lugar:</b>" + lugar.getText() + "</p>")
                    .append("<p><b>Color de vidrio:</b>" + color.getText() + "</p>")
                    .append("<p><b>Milimetraje:</b>" + milimetraje.getText() + "</p>")
                    .append("<p><b>Tipo de abertura:</b>" + abertura.getSelectedItem() + "</p>")
                    .append("<p><b>Largo:</b>" + largo.getText() + "</p>")
                    .append("<p><b>Ancho:</b>" + ancho.getText() + "</p>")
                    .append("<p><bold>Observacion:</bold>" + obs.getText() + "</p>")
                    .toString()
            )
    );


    try {
        startActivity(Intent.createChooser(intent, "Seleccione correo"));
        finish();
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(MainActivity.this, "Error al enviar", Toast.LENGTH_SHORT).show();
    }
}

Any ideas on how to do that? I think that explains me well so that they can understand the problem and be able to help me with a solution, basically it is able to generate several times an opening and that the loaded data is saved to be able to send them in the email.

    
asked by 22.02.2018 в 02:57
source

0 answers