I have to buttons which should start the same activity, but use a different XML file.
What I was hoping to be able to do was something like this, from “main”:
button1: startActivity(new Intent(main.this, next.class, R.layout.xmlfile1));
button2: startActivity(new Intent(main.this, next.class, R.layout.xmlfile2));
I guess I could save the xml-name in the application context / with a global variable, but that wouldn’t be very elegant.
Anyone know if there is any way to accomplish what I’m looking for? At the moment I’m creating duplicate class-files, and that’s not really a smooth way to do it…
You can pass the data to the activity by putting extra data on the Intent.
See the Intent’s method
putExtraandgetIntExtraand friends.The integer you put is the xml resource id.
On the activity you cat use
getIntExtraon the activities intent (getIntent) to retrieve the id.