Retrieve data from other fragments when clicking button?

0

I have a form with 3 Fragments, where in the last there is a save button, when I click on this button I need to get the data entered by the user in Fragment 1 and 2, get the data of the open fragment (3) and save for this I thought of using Singleton where I have a model class that contains all input values, but I do not know how to save the data in this singleton when I exit (Swipe or click another fragment in TabLayout) of Fragment 1 and 2. Someone suggests some solution for me favor.

Function to save data in the Activity through the fragment interface "A":

@Override
public void salvarDadosPessoais(HashMap<String, Object> hashMap) {
    paciente.setNOME(hashMap.get("nome").toString());
    paciente.setDATA_NASC(Utils.obterInstancia().StringToDate(hashMap.get("dataNasc").toString()));
    paciente.setSEXO(hashMap.get("sexo").toString());
    paciente.setTIPO_SANGUINEO(Integer.parseInt(hashMap.get("tipoSanguineo").toString()));
    paciente.setNOME_MAE(hashMap.get("nomeMae").toString());
    paciente.setDESCONHECE_NOME_PAI(Integer.parseInt(hashMap.get("desconhecePai").toString()));
    paciente.setNOME_PAI(hashMap.get("nomePai").toString());
    paciente.setEMAIL(hashMap.get("email").toString());
    paciente.setSTATUS_NACIONALIDADE(Integer.parseInt(hashMap.get("statusNacionalidade").toString()));
    paciente.setNATURALIDADE(hashMap.get("naturalidade").toString());
    paciente.setCODIGO_DOCUMENTO(Integer.parseInt(hashMap.get("codigoDocumento").toString()));
    paciente.setDATA_NATURALIZACAO(Utils.obterInstancia().StringToDate(hashMap.get("dataNaturalizacao").toString()));
    paciente.setPORTARIA_NATURALIZACAO(hashMap.get("portariaNaturalizacao").toString());
    paciente.setDATA_ENTRADA_BRASIL(Utils.obterInstancia().StringToDate(hashMap.get("dataEntradaBrasil").toString()));
    paciente.setCODIGO_UF_NATURALIDADE(hashMap.get("codigoUfNaturalidade").toString());
    paciente.setCODIGO_DOCUMENTO(Integer.parseInt(hashMap.get("codigoDocumento").toString()));
    paciente.setDOCUMENTO(hashMap.get("documento").toString());
    paciente.setCNS(hashMap.get("cns").toString());
    paciente.setPRONTUARIO(hashMap.get("prontuario").toString());
    paciente.setCPF(hashMap.get("cpf").toString());
    paciente.setRG(hashMap.get("rg").toString());
    paciente.setCTPS(hashMap.get("ctps").toString());
    paciente.setCODIGO_RACA_COR(Integer.parseInt(hashMap.get("racaCor").toString()));
}

Function that generates HashMap to send to the activity:

public HashMap<String, Object> persistTransients() {
    HashMap<String, Object> hashMap = new HashMap<>();
    hashMap.put("nome", cadNome.getText().toString());
    hashMap.put("dataNasc", splitReverseJoin(cadDataNasc.getText().toString()));
    hashMap.put("sexo", rootView.findViewById(cadRadGroupSexo.getCheckedRadioButtonId()).getTag().toString());
    Integer tipoSanguineo =  cadTipoSanguineo.getSelectedItemPosition();
    hashMap.put("tipoSanguineo", getResources().getStringArray(R.array.Tipo_Sanguineo_Value)[tipoSanguineo]);
    hashMap.put("nomeMae", cadNomeMae.getText().toString());
    if(cadChkDescPai.isChecked()){
        hashMap.put("desconhecePai", 1);
    }else{
        hashMap.put("desconhecePai", 0);
    }
    hashMap.put("nomePai", cadNomePai.getText().toString());
    hashMap.put("email", cadEmail.getText().toString());
    hashMap.put("statusNacionalidade", rootView.findViewById(cadRadGroupNac.getCheckedRadioButtonId()).getTag());
    hashMap.put("naturalidade", cadMunicipioNasc.getTag().toString());
    Integer paisN = cadPaisNasc.getSelectedItemPosition();
    hashMap.put("codigoDocumento", getResources().getStringArray(R.array.Pais_Nasc_Value)[paisN]);
    hashMap.put("dataNaturalizacao", splitReverseJoin(cadDataNatur.getText().toString()));
    hashMap.put("portariaNaturalizacao", cadPortariaNatu.getText().toString());
    hashMap.put("dataEntradaBrasil", Utils.obterInstancia().StringToDate(splitReverseJoin(cadDataEntrada.getText().toString())));
    Integer estado = cadEstado.getSelectedItemPosition();
    hashMap.put("codigoUfNaturalidade", getResources().getStringArray(R.array.Estados_Value)[estado]);
    Integer tipoDoc = cadTipoDoc.getSelectedItemPosition();
    hashMap.put("codigoDocumento", getResources().getStringArray(R.array.Tipo_Documento_Value)[tipoDoc]);
    hashMap.put("documento", cadDocumento.getText().toString());
    hashMap.put("cns", cadCns.getText().toString());
    hashMap.put("prontuario", cadProntuario.getText().toString());
    hashMap.put("cpf", cadCpf.getText().toString());
    hashMap.put("rg", cadRg.getText().toString());
    hashMap.put("ctps", cadCtps.getText().toString());
    Integer racaCor = cadRacaCor.getSelectedItemPosition();
    hashMap.put("racaCor", getResources().getStringArray(R.array.Raca_Cor_Value)[racaCor]);
    return hashMap;
}
    
asked by anonymous 29.10.2018 / 19:58

0 answers