Android Button Navigation: Click to New Page
To achieve the function of redirecting to a new page by clicking a button, you can use an Intent to start a new Activity. First, add the following code in the click event of your button:
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
MainActivity.this represents the context of the current Activity, and SecondActivity.class is the class of the Activity you want to navigate to. Remember to register your Activity in the AndroidManifest.xml file.
<activity android:name=".SecondActivity"></activity>
After clicking the button, you will be redirected to the SecondActivity page.