jeudi 30 juillet 2015

checkBox checked not working

i'm having some trouble working with there checkbox. So in my app the user as 2 check boxes, and then a button, that button opens a new intent, and i need to pass the information through the intent to know if the checkbox is checked or not. I'm passing that information with the .putExtra() but then in the new intent when i do a if statement my app always crashes here because it gives me always a null pointer exception. Here's the code for the button and pass the information:

final CheckBox sabado = (CheckBox) findViewById(R.id.checkBoxSabado);
    final CheckBox domingo = (CheckBox) findViewById(R.id.checkBoxDomingo);

    //Clique no botao "PROCURAR"
    buttonProcurar.setOnClickListener(
            new Button.OnClickListener(){
                @Override
                public void onClick(View v) {
                    if(deTextPartida.getText().toString().equals(paraTextDestino.getText().toString())){
                        Toast.makeText(getBaseContext(), "Partida e destino nao podem ser iguais, escolha de novo!", Toast.LENGTH_LONG).show();
                    }
                    else{
                        Intent i = new Intent(horariosMenu.this, mostraHorario.class);
                        i.putExtra("Partida", deTextPartida.getText().toString());
                        i.putExtra("Destino", paraTextDestino.getText().toString());
                        i.putExtra("Sabado", sabado.isChecked());
                        i.putExtra("Domingo", domingo.isChecked());
                        startActivity(i);
                    }
                }
            }
    );

And here's the code to get it:

Bundle data = getIntent().getExtras();
    if(data == null){
        return;
    }
    String Partida = data.getString("Partida");
    String Destino = data.getString("Destino");
    String Sabado = data.getString("Sabado");
    String Domingo = data.getString("Domingo");

    if(Sabado.equals("true")){
        Toast.makeText(getBaseContext(), "Sabado", Toast.LENGTH_LONG).show();
    }

What am i doing wrong guys ? :X




Aucun commentaire:

Enregistrer un commentaire