methods of other Ctivity

Asked

Viewed 16 times

0

I’m developing a simulated proof app in it will have several categories of evidence and with checkbox to select which you want to do but I’m unable to call the metadata, appears only the first

Activity das Questoes

public class QuestoesActivity extends AppCompatActivity {

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
private TextView txtQuestao, numeroQuestao;
private LinearLayout opcaoQuestao;
private Button btnProximo;
private int contagem = 0;
public List<QuestoesModel> list;
private int posicao = 0;
private int pontuacao = 0;
private String categoria;
private int setNumero;

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

    txtQuestao = findViewById(R.id.txtQuestao);
    btnProximo = findViewById(R.id.btnProximo);
    opcaoQuestao = findViewById(R.id.opcaoQuestao);
    numeroQuestao = findViewById(R.id.numeroQuestao);

    categoria = getIntent().getStringExtra("categoria");
    setNumero = getIntent().getIntExtra("setNumero", 1);

    list = new ArrayList<>();


    questaoNav();questaoAll();



    for (int i = 0; i < 4; i++){
        opcaoQuestao.getChildAt(i).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                conferirRespostas((Button) v);
            }
        });
    }

    playAnim(txtQuestao, 0, list.get(posicao).getQuestao());
    btnProximo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            btnProximo.setEnabled(false);
            btnProximo.setAlpha(0.7f);
            habilitarOpcao(true);
            posicao++;
            if (posicao == list.size()){
                Intent pontosInt = new Intent(QuestoesActivity.this, PontuacaoActivity.class);
                pontosInt.putExtra("pontuacao", pontuacao);
                pontosInt.putExtra("total", list.size());
                startActivity(pontosInt);
                finish();
                return;
            }
            contagem = 0;
            playAnim(txtQuestao, 0, list.get(posicao).getQuestao());
        }
    });

}

private void playAnim(View view, int value, String data){

    view.animate().alpha(value).scaleX(value).scaleY(value).setDuration(500).setStartDelay(100).setInterpolator(new DecelerateInterpolator()).setListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            if (value == 0 && contagem < 4){
                String opcao = "";

                //Ordem que as opções vão aparecer

                if (contagem == 0){
                    opcao = list.get(posicao).getOpcaoA();
                }else if (contagem == 1){
                    opcao = list.get(posicao).getOpcaoB();
                }else if (contagem == 2){
                    opcao = list.get(posicao).getOpcaoC();
                }else if (contagem == 3){
                    opcao = list.get(posicao).getOpcaoD();
                }
                playAnim(opcaoQuestao.getChildAt(contagem), 0, opcao);
                contagem ++;

            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (value == 0){
                try {
                    ((TextView)view).setText(data);
                    numeroQuestao.setText(posicao + 1 + "/" + list.size());
                }catch (ClassCastException ex){
                    ((Button)view).setText(data);
                }
                view.setTag(data);
                playAnim(view, 1, data);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

}

private void conferirRespostas(Button selecionarOpcao){
    habilitarOpcao(true);
    btnProximo.setEnabled(true);
    btnProximo.setAlpha(1);
    if (selecionarOpcao.getText().toString().equals(list.get(posicao).getRespostaCorreta())){
        pontuacao++;
        selecionarOpcao.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#4CAF50")));

    }else{
        selecionarOpcao.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#4CAF50")));
        Button respostaCorreta = (Button) opcaoQuestao.findViewWithTag(list.get(posicao).getRespostaCorreta());
    }
}

private void habilitarOpcao(boolean habilitar){
    for (int i = 0; i < 4; i++){
        opcaoQuestao.getChildAt(i).setEnabled(habilitar);
        if (habilitar){
            opcaoQuestao.getChildAt(i).setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#7EC6C6C6")));
        }
    }
}

public void questaoNav() {

    list.add(new QuestoesModel(
            "2",
            "a",
            "b",
            "c",
            "d",
            "b"
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
}
public void questaoMet() {

    list.add(new QuestoesModel(
            "3",
            "a",
            "b",
            "c",
            "d",
            "b"
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
}
public void questaoTeo() {

    list.add(new QuestoesModel(
            "4",
            "a",
            "b",
            "c",
            "d",
            "b"
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
}
public void questaoTec() {

    list.add(new QuestoesModel(
            "5",
            "a",
            "b",
            "c",
            "d",
            "b"
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
}
public void questaoReg() {

    list.add(new QuestoesModel(
            "6",
            "a",
            "b",
            "c",
            "d",
            "b"
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
}
public void questaoAll() {

    list.add(new QuestoesModel(
            "7",
            "a",
            "b",
            "c",
            "d",
            "b"
    ));
    list.add(new QuestoesModel(
            "fafdassdf",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
    list.add(new QuestoesModel(
            "",
            "",
            "",
            "",
            "",
            ""
    ));
}

}

Activity Main where will be called the methods when selected the checkbox

public class MainActivity extends QuestoesActivity {

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
private RecyclerView rv;
public List<QuestoesModel> list;
public CheckBox checkNav, checkMet, checkTV, checkRTA, checkCT, checkAll;
public Button btnTeste;
//private Dialog loadingDialog;

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

    //loadingDialog = new Dialog(this);
    //loadingDialog.setContentView(R.layout.loading);
    //loadingDialog.getWindow().setBackgroundDrawable(getDrawable(R.drawable.retangulo_branco_background));
    //loadingDialog.getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    //loadingDialog.setCancelable(false);

    btnTeste = findViewById(R.id.btnTeste);
    checkNav = findViewById(R.id.checkNav);
    checkMet = findViewById(R.id.checkMet);
    checkRTA = findViewById(R.id.checkRTA);
    checkTV = findViewById(R.id.checkTV);
    checkCT = findViewById(R.id.checkCT);
    checkAll = findViewById(R.id.checkAll);

    btnTeste.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (checkAll.isChecked()){
                questaoAll();
                questaoNav();
                Intent intent = new Intent(MainActivity.this, QuestoesActivity.class);
                startActivity(intent);
            }if (checkNav.isChecked()){
                questaoNav();
                Intent intent = new Intent(MainActivity.this, QuestoesActivity.class);
                startActivity(intent);
            }
        }
    });

}

}

When the option is called only appears the questions of the first method that was called in Activity Questoes that in the case is questaoNav(); someone knows me how to call the other methods too?

tTela de seleção

Questões

Outro item selecionado

Aqui deveria aparecer 7 no lugar de pergunta

  • Hello, To have more context so I can help you, you want in case the possibility to select more than one option, and after this selection go to the simulated screen taking into account all selected themes?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.