Create your layout view and add a button. Give the button an id such as "btnExamples". After you created your layout and added your button your next step is to define the buttons properties by accessing the associated java file for your view (by for this example we will use main.java).
Copy and past the code below into your java file (main.java).
Button examples = (Button) findViewById(R.id.
btnExamples);examples.setOnClickListener(
new View.OnClickListener() {public void onClick(View view) {
Intent myIntent =
new Intent(view.getContext(), newPage.class);
startActivityForResult(myIntent, 0);Next you need to copy your current main.java by right clicking and selecting "copy", next you need to past into the same location as your main.java. This is assuming you are using Eclipse for your IDE. Eclipse will prompt you for a new name, type "newPage.java", and vola, you have a new java file that you can now assocate with your new layout.
Do the same steps as above to duplicate your layout file and rename it to "newPage.xml"
No comments:
Post a Comment