Catching multiple boolean values and playing within a variable

1

I needed to get all the answers that are inside boolean respostas1 and play inside another variable so I can send it to the MySQL database.

The way I did it, it turned me all false.

For example, I have 4 questions, it should bring me: true, false, true and false ...

and is returning false false false.

Why is it returning false and how to solve it?

for (int x=0; x<respostas2.length; x++){
for (final String a : ids){
    idPERGUNTAS = a;

}

Log.i("ID da Perguntas", "IDS das Perguntas: "+idPERGUNTAS);
//parametrosPost2.add(new BasicNameValuePair("ids", idPERGUNTAS));

for (String IDPaciente : idPacientes){
    for (int i=0; i < respostas2.length; i++){
        idPACIENTES = IDPaciente;

    }
}

Log.i("ID do Paciente", "IDS dos Pacientes: "+idPACIENTES);
//parametrosPost2.add(new BasicNameValuePair("idNome", idPACIENTES));

for(boolean respostas1 : respostas2){
    RESPOSTAS = respostas1;

}

Log.i("Resposta", "Respostas: "+RESPOSTAS);
//parametrosPost2.add(new BasicNameValuePair("respostas", String.valueOf(RESPOSTAS)));

I have 3 values that I would like to send to the database, so I understood, so that I could send all of them ... pq are several answers ... If I put the answer inside the for, it will return all of them to me so that it will triple ...

    
asked by anonymous 10.11.2014 / 16:33

1 answer

2

You are using a for to take element-to-element from an array and place it inside a Boolean variable. The variable only saves a value, ie every loop of for you throw away the previous stored variable and assign a new one in the same place it overlaps the value.

Try this:

//------------------------------ENVIAR DADOS PARA O BANCO--------------------------

try{

    String urlPost2 = "http://"+l.IP+"/projetotcc/android/respostas.php";
    ArrayList<NameValuePair> parametrosPost2 = new ArrayList<NameValuePair>();

    String idPERGUNTAS = null;
    String idPACIENTES = null;
    boolean RESPOSTAS = false;
    //int intResposta = 0;

  //  
        for (final String a : ids){
            idPERGUNTAS = a;
            Log.i("ID da Perguntas", "IDS das Perguntas: "+idPERGUNTAS);
            parametrosPost2.add(new BasicNameValuePair("ids", idPERGUNTAS));
        }

        for (String IDPaciente : idPacientes){
            for (int i=0; i < respostas2.length; i++){
                idPACIENTES = IDPaciente;
                Log.i("ID do Paciente", "IDS dos Pacientes: "+idPACIENTES);
                parametrosPost2.add(new BasicNameValuePair("idNome", idPACIENTES));
            }
        }

        for(boolean respostas1 : respostas2){
             RESPOSTAS = respostas1;
             Log.i("ID da Resposta", "IDS das Respostas: "+RESPOSTAS);
             parametrosPost2.add(new BasicNameValuePair("respostas", String.valueOf(RESPOSTAS)));
        }

//-----------------------------------FIM - ENVIAR DADOS----------------------------------------
        for (int x=0; x<respostas2.length; x++){
        String respostaRetornada2 = null;

        try{
            respostaRetornada2 = ConexaoHttpClient.executaHttpPost(urlPost2, parametrosPost2);
            Log.i("Entrou", "Entrou");
            String resposta2 = respostaRetornada2.toString();
            resposta2 = resposta2.replaceAll("\s+", "");

            Log.i("Logar", "Resposta: "+resposta2);

            if (resposta.equals("1")){
                Toast.makeText(getBaseContext(), "Respostas gravadas com sucesso!", Toast.LENGTH_LONG).show();
            }else{
                Toast.makeText(getBaseContext(), "Erro ao gravar respostas!", Toast.LENGTH_LONG).show();
            }

        }catch(Exception erro){
            f.mensagemSimples(Activity_Conf_Inicio_Ques.this, "Erro", "Erro: "+erro);
        }
    //}

}
    
10.11.2014 / 17:05