1

I'm a newbie in android. How do I want to redirect to activity after clicking a button? I have a button which be a Floating action button. If user A clicks that button to redirect to activity A, if user B click that button to redirect to activity B, ... Help me to solve it! Thanks for all.

Hungphieu
  • 11
  • 1
  • 4

4 Answers4

2

In xml add the following to the button

android:onClick:"onClick"

Then in your activity:

public void onClick(View view)
{
    Intent i = new Intent(CurrentActivity.this,NextActivity.class);
    startActivity(i);
}
Janwilx72
  • 502
  • 4
  • 18
2

You can register a listener in your code as well:

    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(getApplicationContext(), MyActivity.class));
        }
    });
Rachit
  • 3,173
  • 3
  • 28
  • 45
1

You need to setOnClickListener on the Floating Action Button, you can do that by implementing View.OnClickListener to your ActivityA.

Then simply start a new intent, add the below code to your ActivityA, inside the onClickListener of the Floating Action Button.

Intent i = new Intent(getApplicationContext(), ActivityB.class);
startActivity(i);
hsm59
  • 1,991
  • 19
  • 25
0

put this code in onclick of button

Intent intent = new Intent(this, B.class);
startActivity(intent);
vm345
  • 813
  • 12
  • 28