Filipe Buhatem Filipe Buhatem - 3 years ago 77
Android Question

How do I click on a button that makes an invisible button appear in android?

I need to do a quiz with levels and I would like the next level button to appear only when a certain button was clicked, how to do it? (Please be detailed, because I'm new to java)

Answer Source

Activity A:

btnA.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(ActivityA.this, ActivityB.class);
                    i.putExtra("isAnswerCorrect",true);
                    startActivity(i);
                }
            });

Activity B:

...

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_b);
    boolean isAnswerCorrect = getIntent().getBooleanExtra("isAnswerCorrect", false);
    if (isAnswerCorrect) {
        next_level_btn.setVisibility(View.VISIBLE);
    } else {
        next_level_btn.setVisibility(View.GONE);
    }
}

...

In this case, Activity A is where you are pressing the button and Activity B is the activity you are showing your next level button on,

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download