Rav
Rav

Reputation: 141

Linking a button to a XML page

Basic question but i have checked a number of places and can only find information on pop up messages like toast etc.

How would I be able to link buttonA (stored in fragment xml file) so that it will view activitypage.xml?

Thanks!

Upvotes: 1

Views: 649

Answers (2)

A--C
A--C

Reputation: 36449

One thing you can do make a new Activity for each "Screen". Let's make an example, MyNewActivity. The rest is pretty simple. In your button XML add this line:

android:onClick = "nextActivity"

Then in the Fragment that has contains buttonA, do something like this:

public void nextActivity (View v)
{
  Intent intent = new Intent (getActivity(), MyNewActivity.class); //using getActivity since this is from a fragment
  getActivity().startActivity (intent);
}

make sure that in MyNewActivity you put this line in onCreate

setContentView(R.layout.activitypage);

Upvotes: 2

slybloty
slybloty

Reputation: 6506

In your Activity which inflates your button implement a method to open the desired second Activity when the button is clicked. Either button.setOnClickListener() of a method declared in the xml for the button under the android:onClick="buttonClick" attribute.

Upvotes: 0

Related Questions