how to make a button redirect to another xml page

13,085

Solution 1

Make another activity and use

setContentView(R.layout.your_other_layout);

inside of it.

Then in the onClickListener for your button put this:

Intent i = new Intent(YourActivity.this, YourOtherActivity.class);
startActivity(i);

Solution 2

You can add the onclick listener to your button, so: android:onclick="method_in_your_activity".

In your activity added the method (method_in_your_activity) and add startActivity(NewActivity).

Share:
13,085
Mr.Cosmic
Author by

Mr.Cosmic

Beginner java coder, advanced HTML and DOS coder. "HELLO WORLD!" :D

Updated on June 15, 2022

Comments

  • Mr.Cosmic
    Mr.Cosmic almost 2 years

    I'm making a button in xml, like this:

        <Button
            android:id="@+id/buttondp"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/thisisstringtext" />
    

    and I want it to direct it to another page coded in xml. Can anyone help me out?

  • Pavel Dudka
    Pavel Dudka over 11 years
    sorry for accidental downvote and comment... It supposed to go to some other question