Created
November 19, 2013 19:53
-
-
Save SIRHAMY/7551444 to your computer and use it in GitHub Desktop.
Example Java code demoing how to give a button the functionality to switch between activities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExampleActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//Tells Android which XML file holds this class' information | |
setContentView(R.layout.ExampleActivityXMLFile); | |
//Sets up the chosen button | |
Button demo = (Button) findViewById(R.id.exampleButton); | |
demo.setOnClickListener( new OnClickListener() { | |
@Override | |
public void onClick(View v){ | |
//ExampleActivity is the Activity we're in, TargetActivity is the Activity we'd like to show | |
startActivity(new Intent(ExampleActivity.this, TargetActivity.class)); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment