Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] Recuperar View CheckBox

Porque isso? Você já mapeou tudo no onCreate... pra que mapear de novo?

Ou vc faz o mapeamento no método setCorSelecao ou no onCreate...
Da forma que você fez não vai dar certo.


Att.


--
Carlos Eduardo Simões Pelegrin


2014-03-06 17:34 GMT-03:00 Vinny Valente <irmaocaradepau@gmail.com>:
Galera,

Estou tentando recuperar a View dos meus CheckBox dentro de um metodo do um botão.
Tem como fazer isso? Preciso passar a View pra o método setCorSelecao(View view) 

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

InputStream teste = getResources().openRawResource(R.raw.perguntas);
BufferedReader br = new BufferedReader(new InputStreamReader(teste));

numero = (TextView) findViewById(R.id.numero);
quadroView = (TextView) findViewById(R.id.Quadro);
perguntaView = (TextView) findViewById(R.id.Pergunta);
ra = (CheckBox) findViewById(R.id.ra);
rb = (CheckBox) findViewById(R.id.rb);
rc = (CheckBox) findViewById(R.id.rc);
rd = (CheckBox) findViewById(R.id.rd);
re = (CheckBox) findViewById(R.id.re);
rf = (CheckBox) findViewById(R.id.rf);
rg = (CheckBox) findViewById(R.id.rg);

while (linha != null) {
try {
linha = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
strJson += linha;
}

idioma = "pt-br";
boolean ok = getQuestaoCompleta(strJson, 0, idioma);


Button btnProxima = (Button) findViewById(R.id.proxima);
final Toast toast = Toast.makeText(this, "chegou aqui",
Toast.LENGTH_SHORT);

btnProxima.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
String respostaSelecionada = "";
//setContentView(R.layout.activity_prin);
if (ra.isChecked()) {
respostaSelecionada = "a";
}
if (rb.isChecked())
respostaSelecionada += "b";
if (rc.isChecked())
respostaSelecionada += "c";
if (rd.isChecked())
respostaSelecionada += "d";
if (re.isChecked())
respostaSelecionada += "e";
if (rf.isChecked())
respostaSelecionada += "f";
if (rg.isChecked())
respostaSelecionada += "g";

if (respostaSelecionada.length() == getCorreta().length()) {
//idioma = "en";
//Limpa seleção
ra.setChecked(false);
rb.setChecked(false);
rc.setChecked(false);
rd.setChecked(false);
re.setChecked(false);
rf.setChecked(false);
rg.setChecked(false);
setCorSelecao(Minhaview);
//Retirar
toast.setText("Correta: " + getCorreta()
+ " - Selecionada: " + respostaSelecionada);
toast.show();
//Proxima questão
boolean ok = getQuestaoCompleta(strJson, 1, idioma);
} else {
toast.setText("Selecione somente " + getCorreta().length()
+ " opções!");
toast.show();
}
}
});

}

public void setCorSelecao(View view) {
// Is the view now checked?
boolean checked = ((CheckBox) view).isChecked();

CheckBox ra = (CheckBox) findViewById(R.id.ra);
CheckBox rb = (CheckBox) findViewById(R.id.rb);
CheckBox rc = (CheckBox) findViewById(R.id.rc);
CheckBox rd = (CheckBox) findViewById(R.id.rd);
CheckBox re = (CheckBox) findViewById(R.id.re);
CheckBox rf = (CheckBox) findViewById(R.id.rf);
CheckBox rg = (CheckBox) findViewById(R.id.rg);

// Check which checkbox was clicked
switch (view.getId()) {
case R.id.ra:
if (checked) {
/*
* Toast toast = Toast.makeText(this, getCorreta(),
* Toast.LENGTH_SHORT); toast.show();
*/
ra.setBackgroundResource(R.drawable.style_resposta_selecionada);
} else
ra.setBackgroundResource(R.drawable.style_resposta);
break;
case R.id.rb:
if (checked)
rb.setBackgroundResource(R.drawable.style_resposta_selecionada);
else
rb.setBackgroundResource(R.drawable.style_resposta);
break;
case R.id.rc:
if (checked)
rc.setBackgroundResource(R.drawable.style_resposta_selecionada);
else
rc.setBackgroundResource(R.drawable.style_resposta);
break;
case R.id.rd:
if (checked)
rd.setBackgroundResource(R.drawable.style_resposta_selecionada);
else
rd.setBackgroundResource(R.drawable.style_resposta);
break;
case R.id.re:
if (checked)
re.setBackgroundResource(R.drawable.style_resposta_selecionada);
else
re.setBackgroundResource(R.drawable.style_resposta);
break;
case R.id.rf:
if (checked)
rf.setBackgroundResource(R.drawable.style_resposta_selecionada);
else
rf.setBackgroundResource(R.drawable.style_resposta);
break;
case R.id.rg:
if (checked)
rg.setBackgroundResource(R.drawable.style_resposta_selecionada);
else
rg.setBackgroundResource(R.drawable.style_resposta);
break;
}
}

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário