How to call a method from another Activity using checkbox?

Asked

Viewed 18 times

0

I’m mounting a simulated app and want to call the questions that are in an Activity through another Activity, where have checkbox to select the theme.

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (checkBox.isChecked()) {
                SegundaActivity.gerarNvagacao();
                Intent intent = new Intent(MainActivity.this, SegundaActivity.class);
                startActivity(intent);
            }
        }
    });

Can anyone tell me what to call gerarNavegacao so that questions are opened when the checkbox is selected?

1 answer

-1

//voce chamara a tela desta forma
    button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (checkBox.isChecked()) {
            Intent intent = new Intent(MainActivity.this, SegundaActivity.class);
            intent.putExtra("pergunta", 1);
            startActivity(intent);
        }
    }
});

On Monday you will do.

public class SegundaActivity extends Activity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle bundle = getIntent().getExtras();

    int pergunta = bundle.getInt("pergunta", 0);
    
    switch (pergunta){
        case 1:
            gerarNvagacao();
            //aqui chama as funções da primeira pergunta
            break;
        default:
            //aqui chama pergunta generica
            break;
    }
}

private void gerarNvagacao(){
    //aqui tera suas perguntas e layouts
    setContentView(R.layout.segunda_activity);
}
}

Browser other questions tagged

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