Então Carlos,
Em quinta-feira, 6 de março de 2014 18h20min30s UTC-3, Carlos Pelegrin escreveu:
-- Preciso chamar um metodo setCorSelecao de dentro do onclick do botão, mas preciso passar a View e eu não tenho a view.
Em quinta-feira, 6 de março de 2014 18h20min30s UTC-3, Carlos Pelegrin escreveu:
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 Pelegrin2014-03-06 17:34 GMT-03:00 Vinny Valente <irmaoca...@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)@Overrideprotected 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 blocke.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() { @Overridepublic 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çãora.setChecked(false);rb.setChecked(false);rc.setChecked(false);rd.setChecked(false);re.setChecked(false);rf.setChecked(false);rg.setChecked(false);setCorSelecao(Minhaview);//Retirartoast.setText("Correta: " + getCorreta()+ " - Selecionada: " + respostaSelecionada);toast.show();//Proxima questãoboolean 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 clickedswitch (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); } elsera.setBackgroundResource(R.drawable.style_resposta); break;case R.id.rb:if (checked)rb.setBackgroundResource(R.drawable.style_resposta_ selecionada); elserb.setBackgroundResource(R.drawable.style_resposta); break;case R.id.rc:if (checked)rc.setBackgroundResource(R.drawable.style_resposta_ selecionada); elserc.setBackgroundResource(R.drawable.style_resposta); break;case R.id.rd:if (checked)rd.setBackgroundResource(R.drawable.style_resposta_ selecionada); elserd.setBackgroundResource(R.drawable.style_resposta); break;case R.id.re:if (checked)re.setBackgroundResource(R.drawable.style_resposta_ selecionada); elsere.setBackgroundResource(R.drawable.style_resposta); break;case R.id.rf:if (checked)rf.setBackgroundResource(R.drawable.style_resposta_ selecionada); elserf.setBackgroundResource(R.drawable.style_resposta); break;case R.id.rg:if (checked)rg.setBackgroundResource(R.drawable.style_resposta_ selecionada); elserg.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-...@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.






0 comentários:
Postar um comentário