I have two buttons in one class and those buttons send you to the same class but depending on what button that was pressed it will show different text/images/buttons.
So right now when a button is pressed it send you to the next class and adds some intets, like this:
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle1 = new Bundle();
bundle1.putInt("top", R.drawable.1);
bundle1.putInt("mid", R.drawable.2);
bundle1.putInt("bot", R.drawable.3);
Intent intet1 = new Intent(curclass.this, nextclass.class);
intent1.putExtras(bundle1);
startActivity(intent1);
In the next class I have a bundle for each button but I belive I need to set a if/else on them to make sure it only uses one of the bundles because it does not work properly right now.
So how do I make the “if” thing?
I have tried but I don’t know what to put after “if”.
Something like
"if (button1 = pressed)
(do this)
else if (button2 = pressed)
(do this)"
Thanks in advance!
Sorry if I explain like a idoit, might be because I am one and I just started to program.
EDIT: The problem is that I have two bundles in the second activity that looks like this:
Bundle asd = getIntent().getExtras();
int asdasd = asd.getInt("top");
im1 = (ImageView) findViewById(R.id.imagetop);
im1.setImageResource(newimage);
bu1 = (Button) findViewById(R.id.buttontop);
bu1.setText("blahblah");
And I have the mid and bot one under that and then i have the second bundle which tells the Ints from button2 what images/texts to show and the problem is that it loads that second bundles stuff even if I press button1, which I suspect is caused by the bundles just being there side by side with anything telling them what to do.
I hope that clears it up 🙂
The good thing of get… method of bundles it that you can define a default.
Put this wherever you want, maybe you have a class for constants, or where you better fill it to stay. Since it is static, you can access it wherever you want.
Create “global variables” the uniquely identify your buttons.
Always in your first activity, after the button is pressed
or
Then in the second activity